objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class); $this->modeMock = $this->createMock(Mode::class); $objectManager = new ObjectManager($this); $this->command = $objectManager->getObject( ShowModeCommand::class, ['objectManager' => $this->objectManagerMock] ); $this->objectManagerMock->expects($this->once())->method('create')->willReturn($this->modeMock); } public function testExecute() { $currentMode = 'application-mode'; $this->modeMock->expects($this->once())->method('getMode')->willReturn($currentMode); $tester = new CommandTester($this->command); $tester->execute([]); $this->assertStringContainsString( $currentMode, $tester->getDisplay() ); } }