From 26d245070cd6d7dbc3df3b3449db53e16aa485ae Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Sun, 12 Jun 2016 22:38:11 +0200 Subject: [PATCH 1/2] PHPUnit deprecations --- test/Check/CheckRepositoryTest.php | 20 ++- test/Check/CodeParseCheckTest.php | 4 +- test/Check/ComposerCheckTest.php | 6 +- test/Check/DatabaseCheckTest.php | 4 +- test/Check/FileExistsCheckTest.php | 2 +- test/Check/FunctionRequirementsCheckTest.php | 8 +- test/Check/PhpLintCheckTest.php | 2 +- test/CodeInsertionTest.php | 4 +- test/CodePatcherTest.php | 6 +- test/Command/CreditsCommandTest.php | 6 +- test/Command/HelpCommandTest.php | 2 +- test/Command/MenuCommandInvokerTest.php | 16 +-- test/Command/MenuCommandTest.php | 5 +- test/Command/PrintCommandTest.php | 18 +-- test/Command/VerifyCommandTest.php | 77 +++------- test/CommandRouterTest.php | 136 +++++++++--------- test/ComposerUtil/LockFileParserTest.php | 3 +- test/Event/EventDispatcherTest.php | 43 ++++-- test/Event/EventTest.php | 3 +- .../CheckNotApplicableExceptionTest.php | 4 +- test/Exception/CodeExecutionExceptionTest.php | 11 +- .../ExerciseNotConfiguredExceptionTest.php | 2 +- test/Exercise/AbstractExerciseTest.php | 4 +- test/ExerciseDispatcherTest.php | 66 ++++----- test/ExerciseRendererTest.php | 22 ++- test/ExerciseRepositoryTest.php | 26 ++-- test/ExerciseRunner/CgiRunnerTest.php | 9 +- test/ExerciseRunner/CliRunnerTest.php | 9 +- test/Factory/CliRendererFactoryTest.php | 4 +- test/Factory/EventDispatcherFactoryTest.php | 6 +- test/Factory/MenuFactoryTest.php | 31 ++-- test/Factory/RunnerFactoryTest.php | 13 +- test/Listener/CodePatchListenerTest.php | 13 +- test/Listener/PrepareSolutionListenerTest.php | 15 +- test/Listener/SelfCheckListenerTest.php | 4 +- test/MenuItem/ResetProgressTest.php | 16 +-- test/Output/StdOutputTest.php | 2 +- test/Result/CgiOutRequestFailureTest.php | 8 +- test/Result/CgiOutResultTest.php | 4 +- test/Result/FailureTest.php | 2 +- .../FunctionRequirementsFailureTest.php | 2 +- test/Result/StdOutFailureTest.php | 2 +- test/Result/SuccessTest.php | 2 +- test/ResultAggregatorTest.php | 2 +- .../AbstractResultRendererTest.php | 7 +- .../CgiOutResultRendererTest.php | 14 +- test/ResultRenderer/FailureRendererTest.php | 2 +- ...unctionRequirementsFailureRendererTest.php | 2 +- .../OutputFailureRendererTest.php | 2 +- test/ResultRenderer/ResultsRendererTest.php | 4 +- test/Solution/DirectorySolutionTest.php | 6 +- test/Solution/SolutionFileTest.php | 6 +- test/UserStateSerializerTest.php | 12 +- 53 files changed, 310 insertions(+), 389 deletions(-) diff --git a/test/Check/CheckRepositoryTest.php b/test/Check/CheckRepositoryTest.php index 6ae67103..492e9117 100644 --- a/test/Check/CheckRepositoryTest.php +++ b/test/Check/CheckRepositoryTest.php @@ -16,7 +16,7 @@ class CheckRepositoryTest extends PHPUnit_Framework_TestCase { public function testRegisterViaConstructor() { - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $repository = new CheckRepository([$check]); $this->assertEquals([$check], $repository->getAll()); } @@ -26,7 +26,7 @@ public function testRegisterCheck() $repository = new CheckRepository; $this->assertEquals([], $repository->getAll()); - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $repository->registerCheck($check); $this->assertEquals([$check], $repository->getAll()); } @@ -34,9 +34,9 @@ public function testRegisterCheck() public function testHas() { $repository = new CheckRepository; - $repository->registerCheck($this->getMock(CheckInterface::class)); + $repository->registerCheck($this->createMock(CheckInterface::class)); - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $repository->registerCheck($check); $this->assertTrue($repository->has(get_class($check))); @@ -46,12 +46,10 @@ public function testHas() public function testGetByClassThrowsExceptionIfNotExist() { $repository = new CheckRepository; - $repository->registerCheck($this->getMock(CheckInterface::class)); + $repository->registerCheck($this->createMock(CheckInterface::class)); - $this->setExpectedException( - InvalidArgumentException::class, - 'Check: "SomeClassWhichDoesNotExist" does not exist' - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Check: "SomeClassWhichDoesNotExist" does not exist'); $repository->getByClass('SomeClassWhichDoesNotExist'); } @@ -59,9 +57,9 @@ public function testGetByClassThrowsExceptionIfNotExist() public function testGetByClass() { $repository = new CheckRepository; - $repository->registerCheck($this->getMock(CheckInterface::class)); + $repository->registerCheck($this->createMock(CheckInterface::class)); - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $repository->registerCheck($check); $this->assertSame($check, $repository->getByClass(get_class($check))); diff --git a/test/Check/CodeParseCheckTest.php b/test/Check/CodeParseCheckTest.php index 7dcde70d..7813b28e 100644 --- a/test/Check/CodeParseCheckTest.php +++ b/test/Check/CodeParseCheckTest.php @@ -48,7 +48,7 @@ public function testUnParseableCodeReturnsFailure() { file_put_contents($this->file, 'check->check($this->getMock(ExerciseInterface::class), $this->file); + $result = $this->check->check($this->createMock(ExerciseInterface::class), $this->file); $this->assertInstanceOf(Failure::class, $result); $this->assertEquals('Code Parse Check', $result->getCheckName()); @@ -62,7 +62,7 @@ public function testParseableCodeReturnsSuccess() { file_put_contents($this->file, 'check->check($this->getMock(ExerciseInterface::class), $this->file); + $result = $this->check->check($this->createMock(ExerciseInterface::class), $this->file); $this->assertInstanceOf(Success::class, $result); $this->assertEquals('Code Parse Check', $result->getCheckName()); diff --git a/test/Check/ComposerCheckTest.php b/test/Check/ComposerCheckTest.php index c78b5ef3..4dcabdd3 100644 --- a/test/Check/ComposerCheckTest.php +++ b/test/Check/ComposerCheckTest.php @@ -45,8 +45,8 @@ public function setUp() public function testExceptionIsThrownIfNotValidExercise() { - $exercise = $this->getMock(ExerciseInterface::class); - $this->setExpectedException(InvalidArgumentException::class); + $exercise = $this->createMock(ExerciseInterface::class); + $this->expectException(InvalidArgumentException::class); $this->check->check($exercise, ''); } @@ -77,7 +77,7 @@ public function testCheckReturnsFailureIfNoComposerLockFile() */ public function testCheckReturnsFailureIfDependencyNotRequired($dependency, $solutionFile) { - $exercise = $this->getMock(ComposerExercise::class); + $exercise = $this->createMock(ComposerExercise::class); $exercise->expects($this->once()) ->method('getRequiredPackages') ->will($this->returnValue([$dependency])); diff --git a/test/Check/DatabaseCheckTest.php b/test/Check/DatabaseCheckTest.php index 1a4f6647..90a59347 100644 --- a/test/Check/DatabaseCheckTest.php +++ b/test/Check/DatabaseCheckTest.php @@ -45,7 +45,7 @@ class DatabaseCheckTest extends PHPUnit_Framework_TestCase public function setUp() { $this->check = new DatabaseCheck; - $this->exercise = $this->getMock(DatabaseExerciseInterface::class); + $this->exercise = $this->createMock(DatabaseExerciseInterface::class); $this->dbDir = sprintf( '%s/PhpSchool_PhpWorkshop_Check_DatabaseCheck', str_replace('\\', '/', realpath(sys_get_temp_dir())) @@ -194,7 +194,7 @@ public function testRunExercise() $dispatcher->run( $this->exercise, __DIR__ . '/../res/database/user-solution-alter-db.php', - $this->getMock(OutputInterface::class) + $this->createMock(OutputInterface::class) ); } diff --git a/test/Check/FileExistsCheckTest.php b/test/Check/FileExistsCheckTest.php index b9794f5c..f2e43eb4 100644 --- a/test/Check/FileExistsCheckTest.php +++ b/test/Check/FileExistsCheckTest.php @@ -37,7 +37,7 @@ public function setUp() $this->testDir = sprintf('%s/%s', sys_get_temp_dir(), $this->getName()); mkdir($this->testDir, 0777, true); $this->check = new FileExistsCheck; - $this->exercise = $this->getMock(ExerciseInterface::class); + $this->exercise = $this->createMock(ExerciseInterface::class); $this->assertEquals('File Exists Check', $this->check->getName()); $this->assertEquals(ExerciseInterface::class, $this->check->getExerciseInterface()); $this->assertEquals(SimpleCheckInterface::CHECK_BEFORE, $this->check->getPosition()); diff --git a/test/Check/FunctionRequirementsCheckTest.php b/test/Check/FunctionRequirementsCheckTest.php index d20e0597..4cbbf7b0 100644 --- a/test/Check/FunctionRequirementsCheckTest.php +++ b/test/Check/FunctionRequirementsCheckTest.php @@ -54,8 +54,8 @@ public function setUp() public function testExceptionIsThrownIfNotValidExercise() { - $exercise = $this->getMock(ExerciseInterface::class); - $this->setExpectedException(InvalidArgumentException::class); + $exercise = $this->createMock(ExerciseInterface::class); + $this->expectException(InvalidArgumentException::class); $this->check->check($exercise, ''); } @@ -84,7 +84,7 @@ public function testFailureIsReturnedIfBannedFunctionsAreUsed() public function testFailureIsReturnedIfNotAllRequiredFunctionsHaveBeenUsed() { - $exercise = $this->getMock(FunctionRequirementsExercise::class); + $exercise = $this->createMock(FunctionRequirementsExercise::class); $exercise ->expects($this->once()) ->method('getBannedFunctions') @@ -107,7 +107,7 @@ public function testFailureIsReturnedIfNotAllRequiredFunctionsHaveBeenUsed() public function testSuccess() { - $exercise = $this->getMock(FunctionRequirementsExercise::class); + $exercise = $this->createMock(FunctionRequirementsExercise::class); $exercise ->expects($this->once()) ->method('getBannedFunctions') diff --git a/test/Check/PhpLintCheckTest.php b/test/Check/PhpLintCheckTest.php index 32765cd1..5de561e4 100644 --- a/test/Check/PhpLintCheckTest.php +++ b/test/Check/PhpLintCheckTest.php @@ -31,7 +31,7 @@ class PhpLintCheckTest extends PHPUnit_Framework_TestCase public function setUp() { $this->check = new PhpLintCheck; - $this->exercise = $this->getMock(ExerciseInterface::class); + $this->exercise = $this->createMock(ExerciseInterface::class); $this->assertEquals('PHP Code Check', $this->check->getName()); $this->assertEquals(ExerciseInterface::class, $this->check->getExerciseInterface()); $this->assertEquals(SimpleCheckInterface::CHECK_BEFORE, $this->check->getPosition()); diff --git a/test/CodeInsertionTest.php b/test/CodeInsertionTest.php index 8ecdb006..8f7113e8 100644 --- a/test/CodeInsertionTest.php +++ b/test/CodeInsertionTest.php @@ -15,13 +15,13 @@ class CodeInsertionTest extends PHPUnit_Framework_TestCase { public function testInvalidType() { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new CodeInsertion('notatype', ''); } public function testInvalidCode() { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new CodeInsertion(CodeInsertion::TYPE_BEFORE, new \stdClass); } diff --git a/test/CodePatcherTest.php b/test/CodePatcherTest.php index d4b7149a..7bd2b6e3 100644 --- a/test/CodePatcherTest.php +++ b/test/CodePatcherTest.php @@ -29,7 +29,7 @@ public function testDefaultPatchIsAppliedIfAvailable() ->withInsertion(new Insertion(Insertion::TYPE_BEFORE, 'ini_set("display_errors", 1);')); $patcher = new CodePatcher((new ParserFactory)->create(ParserFactory::PREFER_PHP7), new Standard, $patch); - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $expected = "assertEquals($expected, $patcher->patch($exercise, 'create(ParserFactory::PREFER_PHP7), new Standard); - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $code = 'assertEquals($code, $patcher->patch($exercise, $code)); @@ -56,7 +56,7 @@ public function testPatcher($code, Patch $patch, $expectedResult) { $patcher = new CodePatcher((new ParserFactory)->create(ParserFactory::PREFER_PHP7), new Standard); - $exercise = $this->getMock(PatchableExercise::class); + $exercise = $this->createMock(PatchableExercise::class); $exercise ->expects($this->once()) diff --git a/test/Command/CreditsCommandTest.php b/test/Command/CreditsCommandTest.php index 97e42d53..89be6567 100644 --- a/test/Command/CreditsCommandTest.php +++ b/test/Command/CreditsCommandTest.php @@ -36,7 +36,7 @@ public function testInvoke() '@AydinHassan' => 'Aydin Hassan', '@mikeymike' => 'Michael Woodward', ], - new StdOutput($color, $this->getMock(TerminalInterface::class)), + new StdOutput($color, $this->createMock(TerminalInterface::class)), $color ); @@ -58,7 +58,7 @@ public function testWithOnlyCoreContributors() '@chris3ailey' => 'Chris Bailey' ], [], - new StdOutput($color, $this->getMock(TerminalInterface::class)), + new StdOutput($color, $this->createMock(TerminalInterface::class)), $color ); @@ -75,7 +75,7 @@ public function testWithNoContributors() $command = new CreditsCommand( [], [], - new StdOutput($color, $this->getMock(TerminalInterface::class)), + new StdOutput($color, $this->createMock(TerminalInterface::class)), $color ); diff --git a/test/Command/HelpCommandTest.php b/test/Command/HelpCommandTest.php index 9faf6aac..759e29f5 100644 --- a/test/Command/HelpCommandTest.php +++ b/test/Command/HelpCommandTest.php @@ -24,7 +24,7 @@ public function testInvoke() $command = new HelpCommand( 'learnyouphp', - new StdOutput($color, $this->getMock(TerminalInterface::class)), + new StdOutput($color, $this->createMock(TerminalInterface::class)), $color ); diff --git a/test/Command/MenuCommandInvokerTest.php b/test/Command/MenuCommandInvokerTest.php index 7019acdc..48366761 100644 --- a/test/Command/MenuCommandInvokerTest.php +++ b/test/Command/MenuCommandInvokerTest.php @@ -15,20 +15,20 @@ class MenuCommandInvokerTest extends PHPUnit_Framework_TestCase { public function testInvoker() { - $menu = $this->getMockBuilder(CliMenu::class) - ->disableOriginalConstructor() - ->getMock(); - + $menu = $this->createMock(CliMenu::class); $menu ->expects($this->once()) ->method('close'); - $command = $this->getMock('stdClass', ['myCallBack']); + $command = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $command ->expects($this->once()) - ->method('myCallBack'); - - $invoker = new MenuCommandInvoker([$command, 'myCallBack']); + ->method('__invoke'); + + $invoker = new MenuCommandInvoker($command); $invoker->__invoke($menu); } } diff --git a/test/Command/MenuCommandTest.php b/test/Command/MenuCommandTest.php index 2c423756..78d2db5e 100644 --- a/test/Command/MenuCommandTest.php +++ b/test/Command/MenuCommandTest.php @@ -16,10 +16,7 @@ class MenuCommandTest extends PHPUnit_Framework_TestCase { public function testInvoke() { - $menu = $this->getMockBuilder(CliMenu::class) - ->disableOriginalConstructor() - ->getMock(); - + $menu = $this->createMock(CliMenu::class); $menu ->expects($this->once()) ->method('open'); diff --git a/test/Command/PrintCommandTest.php b/test/Command/PrintCommandTest.php index 52d54d1b..ec1c6f0d 100644 --- a/test/Command/PrintCommandTest.php +++ b/test/Command/PrintCommandTest.php @@ -21,12 +21,8 @@ public function testErrorIsPrintedIfNoExerciseAssigned() { $repo = new ExerciseRepository([]); $state = new UserState; - $output = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $renderer = $this->getMockBuilder(MarkdownRenderer::class) - ->disableOriginalConstructor() - ->getMock(); + $output = $this->createMock(OutputInterface::class); + $renderer = $this->createMock(MarkdownRenderer::class); $output ->expects($this->once()) @@ -42,7 +38,7 @@ public function testExerciseIsPrintedIfAssigned() $file = tempnam(sys_get_temp_dir(), 'pws'); file_put_contents($file, '### Exercise 1'); - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise ->expects($this->once()) ->method('getProblem') @@ -58,12 +54,8 @@ public function testExerciseIsPrintedIfAssigned() $state = new UserState; $state->setCurrentExercise('current-exercise'); - $output = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $renderer = $this->getMockBuilder(MarkdownRenderer::class) - ->disableOriginalConstructor() - ->getMock(); + $output = $this->createMock(OutputInterface::class); + $renderer = $this->createMock(MarkdownRenderer::class); $renderer ->expects($this->once()) diff --git a/test/Command/VerifyCommandTest.php b/test/Command/VerifyCommandTest.php index dca5585b..9587e8ab 100644 --- a/test/Command/VerifyCommandTest.php +++ b/test/Command/VerifyCommandTest.php @@ -34,7 +34,7 @@ class VerifyCommandTest extends PHPUnit_Framework_TestCase public function setUp() { - $this->check = $this->getMock(CheckInterface::class); + $this->check = $this->createMock(CheckInterface::class); $this->check ->expects($this->any()) ->method('getName') @@ -45,13 +45,8 @@ public function testVerifyPrintsErrorIfProgramDoesNotExist() { $repo = new ExerciseRepository([]); $state = new UserState; - $output = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); + $output = $this->createMock(OutputInterface::class); + $dispatcher = $this->createMock(ExerciseDispatcher::class); $programFile = sprintf('%s/%s/program.php', sys_get_temp_dir(), $this->getName()); $output @@ -59,14 +54,9 @@ public function testVerifyPrintsErrorIfProgramDoesNotExist() ->method('printError') ->with(sprintf('Could not verify. File: "%s" does not exist', $programFile)); - $serializer = $this->getMockBuilder(UserStateSerializer::class) - ->disableOriginalConstructor() - ->getMock(); + $serializer = $this->createMock(UserStateSerializer::class); + $renderer = $this->createMock(ResultsRenderer::class); - $renderer = $this->getMockBuilder(ResultsRenderer::class) - ->disableOriginalConstructor() - ->getMock(); - $command = new VerifyCommand($repo, $dispatcher, $state, $serializer, $output, $renderer); $this->assertSame(1, $command->__invoke('appname', $programFile)); } @@ -78,27 +68,17 @@ public function testVerifyPrintsErrorIfNoExerciseAssigned() $repo = new ExerciseRepository([]); $state = new UserState; - $output = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); + $output = $this->createMock(OutputInterface::class); + $dispatcher = $this->createMock(ExerciseDispatcher::class); $output ->expects($this->once()) ->method('printError') ->with('No active exercises. Select one from the menu'); - $serializer = $this->getMockBuilder(UserStateSerializer::class) - ->disableOriginalConstructor() - ->getMock(); + $serializer = $this->createMock(UserStateSerializer::class); + $renderer = $this->createMock(ResultsRenderer::class); - $renderer = $this->getMockBuilder(ResultsRenderer::class) - ->disableOriginalConstructor() - ->getMock(); - $command = new VerifyCommand($repo, $dispatcher, $state, $serializer, $output, $renderer); $this->assertSame(1, $command->__invoke('appname', $file)); @@ -110,7 +90,7 @@ public function testVerifyAddsCompletedExerciseAndReturnsCorrectCodeOnSuccess() $file = tempnam(sys_get_temp_dir(), 'pws'); touch($file); - $e = $this->getMock(ExerciseInterface::class); + $e = $this->createMock(ExerciseInterface::class); $e->expects($this->any()) ->method('getName') ->will($this->returnValue('exercise1')); @@ -119,28 +99,21 @@ public function testVerifyAddsCompletedExerciseAndReturnsCorrectCodeOnSuccess() $state->setCurrentExercise('exercise1'); $color = new Color; $color->setForceStyle(true); - $output = new StdOutput($color, $this->getMock(TerminalInterface::class)); - - $serializer = $this->getMockBuilder(UserStateSerializer::class) - ->disableOriginalConstructor() - ->getMock(); + $output = new StdOutput($color, $this->createMock(TerminalInterface::class)); + $serializer = $this->createMock(UserStateSerializer::class); $serializer ->expects($this->once()) ->method('serialize') ->with($state); - $renderer = $this->getMockBuilder(ResultsRenderer::class) - ->disableOriginalConstructor() - ->getMock(); - + $renderer = $this->createMock(ResultsRenderer::class); + $results = new ResultAggregator; $results->add(new Success($this->check)); - $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); - + $dispatcher = $this->createMock(ExerciseDispatcher::class); + $dispatcher ->expects($this->once()) ->method('verify') @@ -164,7 +137,7 @@ public function testVerifyDoesNotAddCompletedExerciseAndReturnsCorrectCodeOnFail $file = tempnam(sys_get_temp_dir(), 'pws'); touch($file); - $e = $this->getMock(ExerciseInterface::class); + $e = $this->createMock(ExerciseInterface::class); $e->expects($this->any()) ->method('getName') ->will($this->returnValue('exercise1')); @@ -173,28 +146,22 @@ public function testVerifyDoesNotAddCompletedExerciseAndReturnsCorrectCodeOnFail $state->setCurrentExercise('exercise1'); $color = new Color; $color->setForceStyle(true); - $output = new StdOutput($color, $this->getMock(TerminalInterface::class)); + $output = new StdOutput($color, $this->createMock(TerminalInterface::class)); - $serializer = $this->getMockBuilder(UserStateSerializer::class) - ->disableOriginalConstructor() - ->getMock(); + $serializer = $this->createMock(UserStateSerializer::class); $serializer ->expects($this->never()) ->method('serialize') ->with($state); - $renderer = $this->getMockBuilder(ResultsRenderer::class) - ->disableOriginalConstructor() - ->getMock(); + $renderer = $this->createMock(ResultsRenderer::class); $results = new ResultAggregator; $results->add(new Failure($this->check, 'cba')); - $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); - + $dispatcher = $this->createMock(ExerciseDispatcher::class); + $dispatcher ->expects($this->once()) ->method('verify') diff --git a/test/CommandRouterTest.php b/test/CommandRouterTest.php index 06142935..c0b7c778 100644 --- a/test/CommandRouterTest.php +++ b/test/CommandRouterTest.php @@ -20,23 +20,19 @@ class CommandRouterTest extends PHPUnit_Framework_TestCase { public function testInvalidDefaultThrowsException() { - $this->setExpectedException( - InvalidArgumentException::class, - 'Default command: "cmd" is not available' - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Default command: "cmd" is not available'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); new CommandRouter([], 'cmd', $c); } public function testAddCommandThrowsExceptionIfCommandWithSameNameExists() { - $this->setExpectedException( - InvalidArgumentException::class, - 'Command with name: "cmd" already exists' - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Command with name: "cmd" already exists'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); new CommandRouter([ new CommandDefinition('cmd', [], 'service'), new CommandDefinition('cmd', [], 'service'), @@ -45,7 +41,7 @@ public function testAddCommandThrowsExceptionIfCommandWithSameNameExists() public function testConstruct() { - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); new CommandRouter([new CommandDefinition('cmd', [], 'service'),], 'cmd', $c); } @@ -53,13 +49,16 @@ public function testRouteCommandWithNoArgsFromArrayUsesDefaultCommand() { $args = ['app']; - $mock = $this->getMock('stdClass', array('cb')); + $mock = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $mock->expects($this->once()) - ->method('cb') + ->method('__invoke') ->will($this->returnValue(true)); - $c = $this->getMock(ContainerInterface::class); - $router = new CommandRouter([new CommandDefinition('cmd', [], [$mock, 'cb']),], 'cmd', $c); + $c = $this->createMock(ContainerInterface::class); + $router = new CommandRouter([new CommandDefinition('cmd', [], $mock),], 'cmd', $c); $router->route($args); } @@ -68,13 +67,16 @@ public function testRouteCommandWithNoArgsFromArgVUsesDefaultCommand() { $server = $_SERVER; $_SERVER['argv'] = ['app']; - $mock = $this->getMock('stdClass', array('cb')); + $mock = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $mock->expects($this->once()) - ->method('cb') + ->method('__invoke') ->will($this->returnValue(true)); - $c = $this->getMock(ContainerInterface::class); - $router = new CommandRouter([new CommandDefinition('cmd', [], [$mock, 'cb']),], 'cmd', $c); + $c = $this->createMock(ContainerInterface::class); + $router = new CommandRouter([new CommandDefinition('cmd', [], $mock),], 'cmd', $c); $router->route(); $_SERVER = $server; @@ -82,12 +84,10 @@ public function testRouteCommandWithNoArgsFromArgVUsesDefaultCommand() public function testRouteCommandThrowsExceptionIfCommandWithNameNotExist() { - $this->setExpectedException( - CliRouteNotExistsException::class, - 'Command: "not-a-cmd" does not exist' - ); + $this->expectException(CliRouteNotExistsException::class); + $this->expectExceptionMessage('Command: "not-a-cmd" does not exist'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $router = new CommandRouter([new CommandDefinition('cmd', [], function () { }),], 'cmd', $c); $router->route(['app', 'not-a-cmd']); @@ -95,12 +95,10 @@ public function testRouteCommandThrowsExceptionIfCommandWithNameNotExist() public function testRouteCommandThrowsExceptionIfCommandIsMissingAllArguments() { - $this->setExpectedException( - MissingArgumentException::class, - 'Command: "verify" is missing the following arguments: "exercise", "program"' - ); + $this->expectException(MissingArgumentException::class); + $this->expectExceptionMessage('Command: "verify" is missing the following arguments: "exercise", "program"'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $router = new CommandRouter( [new CommandDefinition('verify', ['exercise', 'program'], function () { }),], @@ -112,12 +110,10 @@ public function testRouteCommandThrowsExceptionIfCommandIsMissingAllArguments() public function testRouteCommandThrowsExceptionIfCommandIsMissingArguments() { - $this->setExpectedException( - MissingArgumentException::class, - 'Command: "verify" is missing the following arguments: "program"' - ); + $this->expectException(MissingArgumentException::class); + $this->expectExceptionMessage('Command: "verify" is missing the following arguments: "program"'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $router = new CommandRouter( [new CommandDefinition('verify', ['exercise', 'program'], function () { }),], @@ -129,15 +125,18 @@ public function testRouteCommandThrowsExceptionIfCommandIsMissingArguments() public function testRouteCommandWithArgs() { - $mock = $this->getMock('stdClass', array('cb')); + $mock = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $mock->expects($this->once()) - ->method('cb') + ->method('__invoke') ->with('app', 'some-exercise', 'program.php') ->will($this->returnValue(true)); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $router = new CommandRouter( - [new CommandDefinition('verify', ['exercise', 'program'], [$mock, 'cb']),], + [new CommandDefinition('verify', ['exercise', 'program'], $mock),], 'verify', $c ); @@ -146,12 +145,10 @@ public function testRouteCommandWithArgs() public function testExceptionIsThrownIfCallableNotCallableAndNotContainerReference() { - $this->setExpectedException( - RuntimeException::class, - 'Callable must be a callable or a container entry for a callable service' - ); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Callable must be a callable or a container entry for a callable service'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $router = new CommandRouter( [new CommandDefinition('verify', ['exercise', 'program'], new \stdClass),], 'verify', @@ -162,12 +159,10 @@ public function testExceptionIsThrownIfCallableNotCallableAndNotContainerReferen public function testExceptionIsThrownIfCallableNotCallableAndNotExistingContainerEntry() { - $this->setExpectedException( - RuntimeException::class, - 'Container has no entry named: "some.service"' - ); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Container has no entry named: "some.service"'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $c ->expects($this->once()) @@ -185,12 +180,10 @@ public function testExceptionIsThrownIfCallableNotCallableAndNotExistingContaine public function testExceptionIsThrownIfContainerEntryNotCallable() { - $this->setExpectedException( - RuntimeException::class, - 'Container entry: "some.service" not callable' - ); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Container entry: "some.service" not callable'); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $c ->expects($this->once()) @@ -214,16 +207,17 @@ public function testExceptionIsThrownIfContainerEntryNotCallable() public function testCallableFromContainer() { - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); + + $mock = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); - $mock = $this->getMock('stdClass', array('cb')); $mock->expects($this->once()) - ->method('cb') + ->method('__invoke') ->with('app', 'some-exercise', 'program.php') ->will($this->returnValue(true)); - $cb = [$mock, 'cb']; - $c ->expects($this->once()) ->method('has') @@ -234,7 +228,7 @@ public function testCallableFromContainer() ->expects($this->once()) ->method('get') ->with('some.service') - ->will($this->returnValue($cb)); + ->will($this->returnValue($mock)); $router = new CommandRouter( [new CommandDefinition('verify', ['exercise', 'program'], 'some.service'),], @@ -246,16 +240,17 @@ public function testCallableFromContainer() public function testCallableFromContainerWithIntegerReturnCode() { - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); + + $mock = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); - $mock = $this->getMock('stdClass', array('cb')); $mock->expects($this->once()) - ->method('cb') + ->method('__invoke') ->with('app', 'some-exercise', 'program.php') ->will($this->returnValue(10)); - $cb = [$mock, 'cb']; - $c ->expects($this->once()) ->method('has') @@ -266,7 +261,7 @@ public function testCallableFromContainerWithIntegerReturnCode() ->expects($this->once()) ->method('get') ->with('some.service') - ->will($this->returnValue($cb)); + ->will($this->returnValue($mock)); $router = new CommandRouter( [new CommandDefinition('verify', ['exercise', 'program'], 'some.service'),], @@ -279,15 +274,18 @@ public function testCallableFromContainerWithIntegerReturnCode() public function testRouteCommandSpeltIncorrectlyStillRoutes() { - $mock = $this->getMock('stdClass', array('cb')); + $mock = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $mock->expects($this->once()) - ->method('cb') + ->method('__invoke') ->with('app', 'some-exercise', 'program.php') ->will($this->returnValue(true)); - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $router = new CommandRouter( - [new CommandDefinition('verify', ['exercise', 'program'], [$mock, 'cb']),], + [new CommandDefinition('verify', ['exercise', 'program'], $mock),], 'verify', $c ); diff --git a/test/ComposerUtil/LockFileParserTest.php b/test/ComposerUtil/LockFileParserTest.php index f63b8a28..d92f25f7 100644 --- a/test/ComposerUtil/LockFileParserTest.php +++ b/test/ComposerUtil/LockFileParserTest.php @@ -31,7 +31,8 @@ public function testHasPackage() public function testExceptionIsThrownIfFileNotExists() { - $this->setExpectedException(InvalidArgumentException::class, 'Lock File: "not-a-file" does not exist'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Lock File: "not-a-file" does not exist'); new LockFileParser('not-a-file'); } } diff --git a/test/Event/EventDispatcherTest.php b/test/Event/EventDispatcherTest.php index 27e60e79..a16eef84 100644 --- a/test/Event/EventDispatcherTest.php +++ b/test/Event/EventDispatcherTest.php @@ -35,18 +35,24 @@ public function setUp() public function testOnlyAppropriateListenersAreCalledForEvent() { $e = new Event('some-event', ['arg1' => 1, 'arg2' => 2]); - $mockCallback1 = $this->getMock('stdClass', ['callback']); + $mockCallback1 = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $mockCallback1->expects($this->exactly(2)) - ->method('callback') + ->method('__invoke') ->with($e) ->will($this->returnValue(true)); - $mockCallback2 = $this->getMock('stdClass', ['doNotInvokeMe']); + $mockCallback2 = $this->getMockBuilder('stdClass') + ->setMethods(['doNotInvokeMe']) + ->getMock(); + $mockCallback2->expects($this->never()) ->method('doNotInvokeMe'); $cb = function (Event $e) use ($mockCallback1) { - $mockCallback1->callback($e); + $mockCallback1($e); }; $this->eventDispatcher->listen('some-event', $cb); @@ -60,16 +66,19 @@ public function testOnlyAppropriateListenersAreCalledForEvent() public function testOnlyAppropriateVerifiersAreCalledForEvent() { $e = new Event('some-event', ['arg1' => 1, 'arg2' => 2]); - $result = $this->getMock(ResultInterface::class); + $result = $this->createMock(ResultInterface::class); + + $mockCallback1 = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); - $mockCallback1 = $this->getMock('stdClass', ['callback']); $mockCallback1->expects($this->exactly(2)) - ->method('callback') + ->method('__invoke') ->with($e) ->will($this->returnValue($result)); $cb = function (Event $e) use ($mockCallback1) { - return $mockCallback1->callback($e); + return $mockCallback1($e); }; $this->eventDispatcher->insertVerifier('some-event', $cb); @@ -82,14 +91,17 @@ public function testOnlyAppropriateVerifiersAreCalledForEvent() public function testVerifyReturnIsSkippedIfNotInstanceOfResult() { $e = new Event('some-event', ['arg1' => 1, 'arg2' => 2]); - $mockCallback1 = $this->getMock('stdClass', ['callback']); + $mockCallback1 = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $mockCallback1->expects($this->once()) - ->method('callback') + ->method('__invoke') ->with($e) ->will($this->returnValue(null)); $this->eventDispatcher->insertVerifier('some-event', function (Event $e) use ($mockCallback1) { - $mockCallback1->callback($e); + $mockCallback1($e); }); $this->eventDispatcher->dispatch($e); @@ -100,13 +112,16 @@ public function testListenWithMultipleEvents() { $e1 = new Event('some-event', ['arg1' => 1, 'arg2' => 2]); $e2 = new Event('some-event', ['arg1' => 1, 'arg2' => 2]); - $mockCallback1 = $this->getMock('stdClass', ['callback']); + $mockCallback1 = $this->getMockBuilder('stdClass') + ->setMethods(['__invoke']) + ->getMock(); + $mockCallback1->expects($this->exactly(2)) - ->method('callback') + ->method('__invoke') ->withConsecutive([$e1], [$e2]) ->will($this->returnValue(true)); - $this->eventDispatcher->listen(['some-event', 'second-event'], [$mockCallback1, 'callback']); + $this->eventDispatcher->listen(['some-event', 'second-event'], $mockCallback1); $this->eventDispatcher->dispatch($e1); $this->eventDispatcher->dispatch($e2); } diff --git a/test/Event/EventTest.php b/test/Event/EventTest.php index e88b3ef0..86857486 100644 --- a/test/Event/EventTest.php +++ b/test/Event/EventTest.php @@ -28,7 +28,8 @@ public function testGetParameters() public function testExeceptionIsThrownIfParameterDoesNotExist() { - $this->setExpectedException(InvalidArgumentException::class, 'Parameter: "cool" does not exist'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Parameter: "cool" does not exist'); $e = new Event('super-sweet-event-with-cool-params'); $e->getParameter('cool'); } diff --git a/test/Exception/CheckNotApplicableExceptionTest.php b/test/Exception/CheckNotApplicableExceptionTest.php index 378aabfc..0b2b0805 100644 --- a/test/Exception/CheckNotApplicableExceptionTest.php +++ b/test/Exception/CheckNotApplicableExceptionTest.php @@ -23,7 +23,7 @@ public function testException() public function testFromCheckAndExerciseConstructor() { - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise ->expects($this->once()) ->method('getName') @@ -34,7 +34,7 @@ public function testFromCheckAndExerciseConstructor() ->method('getType') ->will($this->returnValue(ExerciseType::CLI())); - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $check ->expects($this->once()) ->method('getName') diff --git a/test/Exception/CodeExecutionExceptionTest.php b/test/Exception/CodeExecutionExceptionTest.php index fe26f6ae..a4e5d9d8 100644 --- a/test/Exception/CodeExecutionExceptionTest.php +++ b/test/Exception/CodeExecutionExceptionTest.php @@ -21,10 +21,8 @@ public function testException() public function testFromProcessUsesErrorOutputIfNotEmpty() { - $process = $this->getMockBuilder(Process::class) - ->disableOriginalConstructor() - ->getMock(); - + $process = $this->createMock(Process::class); + $process ->expects($this->exactly(2)) ->method('getErrorOutput') @@ -36,10 +34,7 @@ public function testFromProcessUsesErrorOutputIfNotEmpty() public function testFromProcessUsesStdOutputIfErrorOutputEmpty() { - $process = $this->getMockBuilder(Process::class) - ->disableOriginalConstructor() - ->getMock(); - + $process = $this->createMock(Process::class); $process ->expects($this->exactly(1)) ->method('getErrorOutput') diff --git a/test/Exception/ExerciseNotConfiguredExceptionTest.php b/test/Exception/ExerciseNotConfiguredExceptionTest.php index 24c1da35..aee81370 100644 --- a/test/Exception/ExerciseNotConfiguredExceptionTest.php +++ b/test/Exception/ExerciseNotConfiguredExceptionTest.php @@ -21,7 +21,7 @@ public function testException() public function testMissingImplementsConstructor() { - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise ->expects($this->once()) ->method('getName') diff --git a/test/Exercise/AbstractExerciseTest.php b/test/Exercise/AbstractExerciseTest.php index 0f503a8a..695106a2 100644 --- a/test/Exercise/AbstractExerciseTest.php +++ b/test/Exercise/AbstractExerciseTest.php @@ -83,9 +83,7 @@ public function problemProvider() public function testConfigureDoesNothing() { - $dispatcher = $this->getMockBuilder(ExerciseDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); + $dispatcher = $this->createMock(ExerciseDispatcher::class); $exercise = new AbstractExerciseImpl('Array We Go'); $this->assertNull($exercise->configure($dispatcher)); diff --git a/test/ExerciseDispatcherTest.php b/test/ExerciseDispatcherTest.php index f06ca4ec..604c16da 100644 --- a/test/ExerciseDispatcherTest.php +++ b/test/ExerciseDispatcherTest.php @@ -98,7 +98,7 @@ class ExerciseDispatcherTest extends PHPUnit_Framework_TestCase public function setUp() { $this->filesystem = new Filesystem; - $this->check = $this->getMock(SimpleCheckInterface::class); + $this->check = $this->createMock(SimpleCheckInterface::class); $this->check ->expects($this->any()) ->method('getName') @@ -110,12 +110,10 @@ public function setUp() ->willReturn(SimpleCheckInterface::CHECK_BEFORE); $this->checkRepository = new CheckRepository([$this->check]); - $this->runner = $this->getMock(ExerciseRunnerInterface::class); - $this->runnerFactory = $this->getMock(RunnerFactory::class); + $this->runner = $this->createMock(ExerciseRunnerInterface::class); + $this->runnerFactory = $this->createMock(RunnerFactory::class); $this->results = new ResultAggregator; - $this->eventDispatcher = $this->getMockBuilder(EventDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); + $this->eventDispatcher = $this->createMock(EventDispatcher::class); $this->exerciseDispatcher = new ExerciseDispatcher( $this->runnerFactory, @@ -134,8 +132,8 @@ public function setUp() private function createExercise() { - $this->exercise = $this->getMock(ExerciseInterface::class); - $this->solution = $this->getMock(SolutionInterface::class); + $this->exercise = $this->createMock(ExerciseInterface::class); + $this->solution = $this->createMock(SolutionInterface::class); $this->exercise ->expects($this->any()) @@ -161,13 +159,14 @@ private function mockRunner(ExerciseInterface $exercise = null) public function testRequireCheckThrowsExceptionIfCheckDoesNotExist() { - $this->setExpectedException(InvalidArgumentException::class, 'Check: "NotACheck" does not exist'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Check: "NotACheck" does not exist'); $this->exerciseDispatcher->requireCheck('NotACheck'); } public function testRequireCheckThrowsExceptionIfPositionNotValid() { - $check = $this->getMock(SimpleCheckInterface::class); + $check = $this->createMock(SimpleCheckInterface::class); $check ->expects($this->any()) ->method('getName') @@ -178,10 +177,8 @@ public function testRequireCheckThrowsExceptionIfPositionNotValid() ->method('getPosition') ->willReturn('middle'); - $this->setExpectedException( - InvalidArgumentException::class, - 'Parameter: "position" can only be one of: "before", "after" Received: "middle"' - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Parameter: "position" can only be one of: "before", "after" Received: "middle"'); $this->checkRepository->registerCheck($check); $this->exerciseDispatcher->requireCheck(get_class($check)); } @@ -195,7 +192,7 @@ public function testRequireBeforeCheck() public function testRequireAfterCheck() { - $check = $this->getMock(SimpleCheckInterface::class); + $check = $this->createMock(SimpleCheckInterface::class); $check ->expects($this->any()) ->method('getName') @@ -215,7 +212,7 @@ public function testRequireAfterCheck() public function testRequireCheckThrowsExceptionIfCheckIsNotSimpleOrListenable() { - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $check ->expects($this->any()) ->method('getName') @@ -223,16 +220,14 @@ public function testRequireCheckThrowsExceptionIfCheckIsNotSimpleOrListenable() $this->checkRepository->registerCheck($check); - $this->setExpectedException( - InvalidArgumentException::class, - sprintf('Check: "%s" is not a listenable check', get_class($check)) - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf('Check: "%s" is not a listenable check', get_class($check))); $this->exerciseDispatcher->requireCheck(get_class($check)); } public function testRequireListenableCheckAttachesToDispatcher() { - $check = $this->getMock(ListenableCheckInterface::class); + $check = $this->createMock(ListenableCheckInterface::class); $this->checkRepository->registerCheck($check); $check @@ -255,7 +250,8 @@ public function testVerifyThrowsExceptionIfCheckDoesNotSupportExerciseType() $msg = 'Check: "Some Check" cannot process exercise: "Some Exercise" with '; $msg .= 'type: "PhpSchool\PhpWorkshop\ExerciseRunner\CliRunner"'; - $this->setExpectedException(CheckNotApplicableException::class, $msg); + $this->expectException(CheckNotApplicableException::class); + $this->expectExceptionMessage($msg); $this->exerciseDispatcher->verify($this->exercise, ''); } @@ -275,10 +271,8 @@ public function testVerifyThrowsExceptionIfExerciseDoesNotImplementCorrectInterf ->method('getExerciseInterface') ->will($this->returnValue('LolIDoNotExist')); - $this->setExpectedException( - ExerciseNotConfiguredException::class, - 'Exercise: "Some Exercise" should implement interface: "LolIDoNotExist"' - ); + $this->expectException(ExerciseNotConfiguredException::class); + $this->expectExceptionMessage('Exercise: "Some Exercise" should implement interface: "LolIDoNotExist"'); $this->exerciseDispatcher->verify($this->exercise, ''); } @@ -312,7 +306,7 @@ public function testVerify() ->expects($this->once()) ->method('verify') ->with($this->file) - ->will($this->returnValue($this->getMock(SuccessInterface::class))); + ->will($this->returnValue($this->createMock(SuccessInterface::class))); $this->exerciseDispatcher->requireCheck(get_class($this->check)); @@ -329,7 +323,10 @@ public function testVerifyOnlyRunsRequiredChecks() ->method('check') ->will($this->returnValue(new Success('Success', 'nope'))); - $doNotRunMe = $this->getMock(SimpleCheckInterface::class, [], [], 'DoNotRunMeCheck'); + $doNotRunMe = $this->getMockBuilder(SimpleCheckInterface::class) + ->setMockClassName('DoNotRunMeCheck') + ->getMock(); + $doNotRunMe ->expects($this->never()) ->method('check'); @@ -350,7 +347,7 @@ public function testVerifyOnlyRunsRequiredChecks() ->expects($this->once()) ->method('verify') ->with($this->file) - ->will($this->returnValue($this->getMock(SuccessInterface::class))); + ->will($this->returnValue($this->createMock(SuccessInterface::class))); $this->checkRepository->registerCheck($doNotRunMe); @@ -370,7 +367,10 @@ public function testWhenBeforeChecksFailTheyReturnImmediately() ->method('check') ->will($this->returnValue(new Failure('Failure', 'nope'))); - $doNotRunMe = $this->getMock(SimpleCheckInterface::class, [], [], 'DoNotRunMeCheck'); + $doNotRunMe = $this->getMockBuilder(SimpleCheckInterface::class) + ->setMockClassName('DoNotRunMeCheck') + ->getMock(); + $doNotRunMe ->expects($this->once()) ->method('getPosition') @@ -454,14 +454,14 @@ public function testVerifyPostExecuteIsStillDispatchedEvenIfRunnerThrowsExceptio ->with($this->file) ->will($this->throwException(new RuntimeException)); - $this->setExpectedException(RuntimeException::class); + $this->expectException(RuntimeException::class); $this->exerciseDispatcher->verify($this->exercise, $this->file); } public function testRun() { - $exercise = $this->getMock(ExerciseInterface::class); - $output = $this->getMock(OutputInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); + $output = $this->createMock(OutputInterface::class); $this->mockRunner($exercise); $this->runner diff --git a/test/ExerciseRendererTest.php b/test/ExerciseRendererTest.php index d0a68604..1f7396bf 100644 --- a/test/ExerciseRendererTest.php +++ b/test/ExerciseRendererTest.php @@ -27,11 +27,9 @@ class ExerciseRendererTest extends PHPUnit_Framework_TestCase { public function testExerciseRendererSetsCurrentExerciseAndRendersExercise() { - $menu = $this->getMockBuilder(CliMenu::class) - ->disableOriginalConstructor() - ->getMock(); + $menu = $this->createMock(CliMenu::class); - $item = $this->getMock(MenuItemInterface::class); + $item = $this->createMock(MenuItemInterface::class); $item ->expects($this->any()) ->method('getText') @@ -45,16 +43,12 @@ public function testExerciseRendererSetsCurrentExerciseAndRendersExercise() ->expects($this->once()) ->method('close'); - $exercise1 = $this->getMock(ExerciseInterface::class); - $exercise2 = $this->getMock(ExerciseInterface::class); + $exercise1 = $this->createMock(ExerciseInterface::class); + $exercise2 = $this->createMock(ExerciseInterface::class); $exercises = [$exercise1, $exercise2]; - $exerciseRepository = $this->getMockBuilder(ExerciseRepository::class) - ->disableOriginalConstructor() - ->getMock(); - $userState = $this->getMock(UserState::class); - $userStateSerializer = $this->getMockBuilder(UserStateSerializer::class) - ->disableOriginalConstructor() - ->getMock(); + $exerciseRepository = $this->createMock(ExerciseRepository::class); + $userState = $this->createMock(UserState::class); + $userStateSerializer = $this->createMock(UserStateSerializer::class); $exerciseRepository ->expects($this->once()) @@ -102,7 +96,7 @@ public function testExerciseRendererSetsCurrentExerciseAndRendersExercise() $userStateSerializer, $markdownRenderer, $color, - new StdOutput($color, $this->getMock(TerminalInterface::class)) + new StdOutput($color, $this->createMock(TerminalInterface::class)) ); $this->expectOutputString(file_get_contents(__DIR__ . '/res/exercise-help-expected.txt')); diff --git a/test/ExerciseRepositoryTest.php b/test/ExerciseRepositoryTest.php index 9cf9f545..bc32f934 100644 --- a/test/ExerciseRepositoryTest.php +++ b/test/ExerciseRepositoryTest.php @@ -17,8 +17,8 @@ class ExerciseRepositoryTest extends PHPUnit_Framework_TestCase public function testFindAll() { $exercises = [ - $this->getMock(ExerciseInterface::class), - $this->getMock(ExerciseInterface::class), + $this->createMock(ExerciseInterface::class), + $this->createMock(ExerciseInterface::class), ]; $repo = new ExerciseRepository($exercises); @@ -28,8 +28,8 @@ public function testFindAll() public function testFindByName() { - $exercise1 = $this->getMock(ExerciseInterface::class); - $exercise2 = $this->getMock(ExerciseInterface::class); + $exercise1 = $this->createMock(ExerciseInterface::class); + $exercise2 = $this->createMock(ExerciseInterface::class); $exercise1 ->expects($this->any()) @@ -47,10 +47,8 @@ public function testFindByName() public function testFindByNameThrowsExceptionIfNotFound() { - $this->setExpectedException( - InvalidArgumentException::class, - 'Exercise with name: "exercise1" does not exist' - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Exercise with name: "exercise1" does not exist'); $repo = new ExerciseRepository([]); $repo->findByName('exercise1'); @@ -58,8 +56,8 @@ public function testFindByNameThrowsExceptionIfNotFound() public function testGetAllNames() { - $exercise1 = $this->getMock(ExerciseInterface::class); - $exercise2 = $this->getMock(ExerciseInterface::class); + $exercise1 = $this->createMock(ExerciseInterface::class); + $exercise2 = $this->createMock(ExerciseInterface::class); $exercise1 ->expects($this->any()) @@ -78,8 +76,8 @@ public function testGetAllNames() public function testCount() { $exercises = [ - $this->getMock(ExerciseInterface::class), - $this->getMock(ExerciseInterface::class), + $this->createMock(ExerciseInterface::class), + $this->createMock(ExerciseInterface::class), ]; $repo = new ExerciseRepository($exercises); @@ -89,8 +87,8 @@ public function testCount() public function testIterator() { $exercises = [ - $this->getMock(ExerciseInterface::class), - $this->getMock(ExerciseInterface::class), + $this->createMock(ExerciseInterface::class), + $this->createMock(ExerciseInterface::class), ]; $repo = new ExerciseRepository($exercises); diff --git a/test/ExerciseRunner/CgiRunnerTest.php b/test/ExerciseRunner/CgiRunnerTest.php index dd5f37b2..5019580d 100644 --- a/test/ExerciseRunner/CgiRunnerTest.php +++ b/test/ExerciseRunner/CgiRunnerTest.php @@ -37,7 +37,7 @@ class CgiRunnerTest extends PHPUnit_Framework_TestCase public function setUp() { - $this->exercise = $this->getMock(CgiExerciseInterface::class); + $this->exercise = $this->createMock(CgiExerciseInterface::class); $this->runner = new CgiRunner($this->exercise, new EventDispatcher(new ResultAggregator)); $this->exercise @@ -66,7 +66,8 @@ public function testVerifyThrowsExceptionIfSolutionFailsExecution() ->will($this->returnValue([$request])); $regex = "/^PHP Code failed to execute\\. Error: \"PHP Parse error: syntax error, unexpected end of file in/"; - $this->setExpectedExceptionRegExp(SolutionExecutionException::class, $regex); + $this->expectException(SolutionExecutionException::class); + $this->expectExceptionMessageRegExp($regex); $this->runner->verify(''); } @@ -247,7 +248,7 @@ public function testRunPassesOutputAndReturnsSuccessIfAllRequestsAreSuccessful() { $color = new Color; $color->setForceStyle(true); - $output = new StdOutput($color, $this->getMock(TerminalInterface::class)); + $output = new StdOutput($color, $this->createMock(TerminalInterface::class)); $request1 = (new Request) ->withMethod('GET') ->withUri(new Uri('http://some.site?number=5')); @@ -292,7 +293,7 @@ public function testRunPassesOutputAndReturnsFailureIfARequestFails() { $color = new Color; $color->setForceStyle(true); - $output = new StdOutput($color, $this->getMock(TerminalInterface::class)); + $output = new StdOutput($color, $this->createMock(TerminalInterface::class)); $request1 = (new Request) ->withMethod('GET') ->withUri(new Uri('http://some.site?number=5')); diff --git a/test/ExerciseRunner/CliRunnerTest.php b/test/ExerciseRunner/CliRunnerTest.php index 203544ae..69692319 100644 --- a/test/ExerciseRunner/CliRunnerTest.php +++ b/test/ExerciseRunner/CliRunnerTest.php @@ -34,7 +34,7 @@ class CliRunnerTest extends PHPUnit_Framework_TestCase public function setUp() { - $this->exercise = $this->getMock(CliExerciseInterface::class); + $this->exercise = $this->createMock(CliExerciseInterface::class); $this->runner = new CliRunner($this->exercise, new EventDispatcher(new ResultAggregator)); $this->exercise @@ -60,7 +60,8 @@ public function testVerifyThrowsExceptionIfSolutionFailsExecution() $regex = "/^PHP Code failed to execute\\. Error: \"PHP Parse error: syntax error, unexpected end of file"; $regex .= ", expecting ',' or ';'/"; - $this->setExpectedExceptionRegExp(SolutionExecutionException::class, $regex); + $this->expectException(SolutionExecutionException::class); + $this->expectExceptionMessageRegExp($regex); $this->runner->verify(''); } @@ -127,7 +128,7 @@ public function testVerifyReturnsFailureIfSolutionOutputDoesNotMatchUserOutput() public function testRunPassesOutputAndReturnsSuccessIfScriptIsSuccessful() { - $output = new StdOutput(new Color, $this->getMock(TerminalInterface::class)); + $output = new StdOutput(new Color, $this->createMock(TerminalInterface::class)); $this->exercise ->expects($this->once()) @@ -148,7 +149,7 @@ public function testRunPassesOutputAndReturnsSuccessIfScriptIsSuccessful() public function testRunPassesOutputAndReturnsFailureIfScriptFails() { - $output = new StdOutput(new Color, $this->getMock(TerminalInterface::class)); + $output = new StdOutput(new Color, $this->createMock(TerminalInterface::class)); $this->exercise ->expects($this->once()) diff --git a/test/Factory/CliRendererFactoryTest.php b/test/Factory/CliRendererFactoryTest.php index c594e2e6..51143fa0 100644 --- a/test/Factory/CliRendererFactoryTest.php +++ b/test/Factory/CliRendererFactoryTest.php @@ -17,7 +17,7 @@ class CliRendererFactoryTest extends PHPUnit_Framework_TestCase { public function testFactoryReturnsInstance() { - $terminal = $this->getMock(TerminalInterface::class); + $terminal = $this->createMock(TerminalInterface::class); $terminal ->expects($this->once()) ->method('getWidth') @@ -28,7 +28,7 @@ public function testFactoryReturnsInstance() Color::class => new Color, ]; - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $c->expects($this->any()) ->method('get') ->will($this->returnCallback(function ($service) use ($services) { diff --git a/test/Factory/EventDispatcherFactoryTest.php b/test/Factory/EventDispatcherFactoryTest.php index aba9b167..79f76f13 100644 --- a/test/Factory/EventDispatcherFactoryTest.php +++ b/test/Factory/EventDispatcherFactoryTest.php @@ -21,7 +21,7 @@ class EventDispatcherFactoryTest extends PHPUnit_Framework_TestCase public function testCreate() { - $c = $this->getMock(ContainerInterface::class); + $c = $this->createMock(ContainerInterface::class); $c->expects($this->at(0)) ->method('get') @@ -35,9 +35,7 @@ public function testCreate() ->with(PrepareSolutionListener::class) ->will($this->returnValue($prepareSolutionListener)); - $codePatchListener = $this->getMockBuilder(CodePatchListener::class) - ->disableOriginalConstructor() - ->getMock(); + $codePatchListener = $this->createMock(CodePatchListener::class); $c->expects($this->at(2)) ->method('get') diff --git a/test/Factory/MenuFactoryTest.php b/test/Factory/MenuFactoryTest.php index a2676bd9..0d31d475 100644 --- a/test/Factory/MenuFactoryTest.php +++ b/test/Factory/MenuFactoryTest.php @@ -24,22 +24,15 @@ class MenuFactoryTest extends PHPUnit_Framework_TestCase { public function testFactoryReturnsInstance() { - $container = $this->getMock(ContainerInterface::class); - - $userStateSerializer = $this->getMockBuilder(UserStateSerializer::class) - ->disableOriginalConstructor() - ->getMock(); - + $container = $this->createMock(ContainerInterface::class); + $userStateSerializer = $this->createMock(UserStateSerializer::class); $userStateSerializer ->expects($this->once()) ->method('deSerialize') ->will($this->returnValue(new UserState)); - $exerciseRepository = $this->getMockBuilder(ExerciseRepository::class) - ->disableOriginalConstructor() - ->getMock(); - - $exercise = $this->getMock(ExerciseInterface::class); + $exerciseRepository = $this->createMock(ExerciseRepository::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise->expects($this->exactly(2)) ->method('getName') ->will($this->returnValue('Exercise')); @@ -51,18 +44,10 @@ public function testFactoryReturnsInstance() $services = [ UserStateSerializer::class => $userStateSerializer, ExerciseRepository::class => $exerciseRepository, - ExerciseRenderer::class => $this->getMockBuilder(ExerciseRenderer::class) - ->disableOriginalConstructor() - ->getMock(), - HelpCommand::class => $this->getMockBuilder(HelpCommand::class) - ->disableOriginalConstructor() - ->getMock(), - CreditsCommand::class => $this->getMockBuilder(CreditsCommand::class) - ->disableOriginalConstructor() - ->getMock(), - ResetProgress::class => $this->getMockBuilder(ResetProgress::class) - ->disableOriginalConstructor() - ->getMock(), + ExerciseRenderer::class => $this->createMock(ExerciseRenderer::class), + HelpCommand::class => $this->createMock(HelpCommand::class), + CreditsCommand::class => $this->createMock(CreditsCommand::class), + ResetProgress::class => $this->createMock(ResetProgress::class), 'workshopLogo' => 'LOGO', 'bgColour' => 'black', 'fgColour' => 'green', diff --git a/test/Factory/RunnerFactoryTest.php b/test/Factory/RunnerFactoryTest.php index 0c7350b6..01b82bcc 100644 --- a/test/Factory/RunnerFactoryTest.php +++ b/test/Factory/RunnerFactoryTest.php @@ -24,21 +24,20 @@ class RunnerFactoryTest extends PHPUnit_Framework_TestCase { public function testExceptionIsThrownIfTypeNotSupported() { - $type = $this->getMockBuilder(ExerciseType::class) - ->disableOriginalConstructor() - ->getMock(); + $type = $this->createMock(ExerciseType::class); $type ->expects($this->exactly(2)) ->method('getValue') ->will($this->returnValue('invalid')); - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise ->expects($this->exactly(2)) ->method('getType') ->will($this->returnValue($type)); - $this->setExpectedException(InvalidArgumentException::class, 'Exercise Type: "invalid" not supported'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Exercise Type: "invalid" not supported'); (new RunnerFactory)->create($exercise, new EventDispatcher(new ResultAggregator)); } @@ -48,13 +47,13 @@ public function testCliAndCgiRunnerCanBeCreated() $cliType = new ExerciseType(ExerciseType::CLI); $cgiType = new ExerciseType(ExerciseType::CGI); - $cliExercise = $this->getMock(CliExerciseInterface::class); + $cliExercise = $this->createMock(CliExerciseInterface::class); $cliExercise ->expects($this->once()) ->method('getType') ->will($this->returnValue($cliType)); - $cgiExercise = $this->getMock(CgiExerciseInterface::class); + $cgiExercise = $this->createMock(CgiExerciseInterface::class); $cgiExercise ->expects($this->once()) ->method('getType') diff --git a/test/Listener/CodePatchListenerTest.php b/test/Listener/CodePatchListenerTest.php index de3a7dda..972188a1 100644 --- a/test/Listener/CodePatchListenerTest.php +++ b/test/Listener/CodePatchListenerTest.php @@ -35,9 +35,7 @@ class CodePatchListenerTest extends PHPUnit_Framework_TestCase public function setUp() { $this->filesystem = new Filesystem; - $this->codePatcher = $this->getMockBuilder(CodePatcher::class) - ->disableOriginalConstructor() - ->getMock(); + $this->codePatcher = $this->createMock(CodePatcher::class); $this->file = sprintf('%s/%s/submission.php', str_replace('\\', '/', sys_get_temp_dir()), $this->getName()); mkdir(dirname($this->file), 0775, true); @@ -47,12 +45,13 @@ public function setUp() public function testRevertThrowsExceptionIfPatchNotPreviouslyCalled() { $fileName = $this->file; - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $listener = new CodePatchListener($this->codePatcher); $event = new Event('event', compact('exercise', 'fileName')); - $this->setExpectedException(RuntimeException::class, 'Can only revert previously patched code'); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Can only revert previously patched code'); $listener->revert($event); } @@ -61,7 +60,7 @@ public function testPatchUpdatesCode() file_put_contents($this->file, 'ORIGINAL CONTENT'); $fileName = $this->file; - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $this->codePatcher ->expects($this->once()) @@ -81,7 +80,7 @@ public function testRevertAfterPatch() file_put_contents($this->file, 'ORIGINAL CONTENT'); $fileName = $this->file; - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $this->codePatcher ->expects($this->once()) diff --git a/test/Listener/PrepareSolutionListenerTest.php b/test/Listener/PrepareSolutionListenerTest.php index 67b2abf0..c920c9ed 100644 --- a/test/Listener/PrepareSolutionListenerTest.php +++ b/test/Listener/PrepareSolutionListenerTest.php @@ -49,8 +49,8 @@ public function testIfSolutionRequiresComposerButComposerCannotBeLocatedExceptio $refProp->setAccessible(true); $refProp->setValue($this->listener, []); - $solution = $this->getMock(SolutionInterface::class); - $exercise = $this->getMock(ExerciseInterface::class); + $solution = $this->createMock(SolutionInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise->expects($this->any()) ->method('getSolution') ->will($this->returnValue($solution)); @@ -60,7 +60,8 @@ public function testIfSolutionRequiresComposerButComposerCannotBeLocatedExceptio ->method('hasComposerFile') ->will($this->returnValue(true)); - $this->setExpectedException(RuntimeException::class, 'Composer could not be located on the system'); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Composer could not be located on the system'); $e = new Event('epic-event', ['exercise' => $exercise, 'file' => 'file.php']); $this->listener->__invoke($e); } @@ -70,8 +71,8 @@ public function testIfSolutionRequiresComposerButVendorDirExistsNothingIsDone() mkdir(sprintf('%s/vendor', dirname($this->file))); $this->assertFileExists(sprintf('%s/vendor', dirname($this->file))); - $solution = $this->getMock(SolutionInterface::class); - $exercise = $this->getMock(ExerciseInterface::class); + $solution = $this->createMock(SolutionInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise->expects($this->any()) ->method('getSolution') ->will($this->returnValue($solution)); @@ -103,8 +104,8 @@ public function testIfSolutionRequiresComposerComposerInstallIsExecuted() ], ])); - $solution = $this->getMock(SolutionInterface::class); - $exercise = $this->getMock(ExerciseInterface::class); + $solution = $this->createMock(SolutionInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $exercise->expects($this->any()) ->method('getSolution') ->will($this->returnValue($solution)); diff --git a/test/Listener/SelfCheckListenerTest.php b/test/Listener/SelfCheckListenerTest.php index f1819120..97d27236 100644 --- a/test/Listener/SelfCheckListenerTest.php +++ b/test/Listener/SelfCheckListenerTest.php @@ -19,7 +19,7 @@ class SelfCheckListenerTest extends PHPUnit_Framework_TestCase { public function testSelfCheck() { - $exercise = $this->getMock(SelfCheckExerciseInterface::class); + $exercise = $this->createMock(SelfCheckExerciseInterface::class); $event = new Event('event', ['exercise' => $exercise, 'fileName' => 'some-file.php']); $success = new Success('Success'); @@ -39,7 +39,7 @@ public function testSelfCheck() public function testExerciseWithOutSelfCheck() { - $exercise = $this->getMock(ExerciseInterface::class); + $exercise = $this->createMock(ExerciseInterface::class); $event = new Event('event', ['exercise' => $exercise, 'fileName' => 'some-file.php']); $results = new ResultAggregator; diff --git a/test/MenuItem/ResetProgressTest.php b/test/MenuItem/ResetProgressTest.php index 878ee519..0ba0f985 100644 --- a/test/MenuItem/ResetProgressTest.php +++ b/test/MenuItem/ResetProgressTest.php @@ -18,23 +18,14 @@ class ResetProgressTest extends PHPUnit_Framework_TestCase { public function testResetProgress() { - $menu = $this->getMockBuilder(CliMenu::class) - ->disableOriginalConstructor() - ->getMock(); - - $userStateSerializer = $this->getMockBuilder(UserStateSerializer::class) - ->disableOriginalConstructor() - ->getMock(); - + $menu = $this->createMock(CliMenu::class); + $userStateSerializer = $this->createMock(UserStateSerializer::class); $userStateSerializer ->expects($this->once()) ->method('serialize') ->with($this->isInstanceOf(UserState::class)); - $output = $this->getMockBuilder(OutputInterface::class) - ->disableOriginalConstructor() - ->getMock(); - + $output = $this->createMock(OutputInterface::class); $output ->expects($this->once()) ->method('writeLine') @@ -42,6 +33,5 @@ public function testResetProgress() $resetProgress = new ResetProgress($userStateSerializer, $output); $resetProgress->__invoke($menu); - } } diff --git a/test/Output/StdOutputTest.php b/test/Output/StdOutputTest.php index ee91292d..a50a578e 100644 --- a/test/Output/StdOutputTest.php +++ b/test/Output/StdOutputTest.php @@ -30,7 +30,7 @@ public function setUp() { $this->color = new Color(); $this->color->setForceStyle(true); - $this->output = new StdOutput($this->color, $this->getMock(TerminalInterface::class)); + $this->output = new StdOutput($this->color, $this->createMock(TerminalInterface::class)); } public function testPrintError() diff --git a/test/Result/CgiOutRequestFailureTest.php b/test/Result/CgiOutRequestFailureTest.php index ce8dde2e..7568c4ec 100644 --- a/test/Result/CgiOutRequestFailureTest.php +++ b/test/Result/CgiOutRequestFailureTest.php @@ -20,7 +20,7 @@ class CgiOutRequestFailureTest extends PHPUnit_Framework_TestCase { public function setUp() { - $request = $this->getMock(RequestInterface::class); + $request = $this->createMock(RequestInterface::class); $cgiOutResult = new CgiOutRequestFailure($request, '', '', [], []); $this->assertSame('Request Failure', $cgiOutResult->getCheckName()); $this->assertSame($request, $cgiOutResult->getRequest()); @@ -29,7 +29,7 @@ public function setUp() public function testWhenOnlyOutputDifferent() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'Expected Output', 'Actual Output', [], @@ -47,7 +47,7 @@ public function testWhenOnlyOutputDifferent() public function testWhenOnlyHeadersDifferent() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'Output', 'Output', ['header1' => 'some-value'], @@ -65,7 +65,7 @@ public function testWhenOnlyHeadersDifferent() public function testWhenOutputAndHeadersDifferent() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'Expected Output', 'Actual Output', ['header1' => 'some-value'], diff --git a/test/Result/CgiOutResultTest.php b/test/Result/CgiOutResultTest.php index 4453481d..77309011 100644 --- a/test/Result/CgiOutResultTest.php +++ b/test/Result/CgiOutResultTest.php @@ -19,14 +19,14 @@ class CgiOutResultTest extends PHPUnit_Framework_TestCase { public function testName() { - $request = new CgiOutRequestFailure($this->getMock(RequestInterface::class), '', '', [], []); + $request = new CgiOutRequestFailure($this->createMock(RequestInterface::class), '', '', [], []); $cgiOutResult = new CgiOutResult('Some Check', [$request]); $this->assertSame('Some Check', $cgiOutResult->getCheckName()); } public function testIsSuccessful() { - $request = new CgiOutRequestFailure($this->getMock(RequestInterface::class), '', '', [], []); + $request = new CgiOutRequestFailure($this->createMock(RequestInterface::class), '', '', [], []); $cgiOutResult = new CgiOutResult('Some Check', [$request]); $this->assertFalse($cgiOutResult->isSuccessful()); diff --git a/test/Result/FailureTest.php b/test/Result/FailureTest.php index 001fc735..4246c168 100644 --- a/test/Result/FailureTest.php +++ b/test/Result/FailureTest.php @@ -23,7 +23,7 @@ class FailureTest extends PHPUnit_Framework_TestCase public function setUp() { - $this->check = $this->getMock(CheckInterface::class); + $this->check = $this->createMock(CheckInterface::class); $this->check ->expects($this->any()) ->method('getName') diff --git a/test/Result/FunctionRequirementsFailureTest.php b/test/Result/FunctionRequirementsFailureTest.php index 30e663c6..7fc699d6 100644 --- a/test/Result/FunctionRequirementsFailureTest.php +++ b/test/Result/FunctionRequirementsFailureTest.php @@ -15,7 +15,7 @@ class FunctionRequirementsFailureTest extends PHPUnit_Framework_TestCase { public function testGetters() { - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $check ->expects($this->any()) ->method('getName') diff --git a/test/Result/StdOutFailureTest.php b/test/Result/StdOutFailureTest.php index da0555e8..b1cb4278 100644 --- a/test/Result/StdOutFailureTest.php +++ b/test/Result/StdOutFailureTest.php @@ -23,7 +23,7 @@ public function testGetters() public function testFailureFromCheck() { - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $check ->expects($this->any()) ->method('getName') diff --git a/test/Result/SuccessTest.php b/test/Result/SuccessTest.php index d1feff35..43fed1f9 100644 --- a/test/Result/SuccessTest.php +++ b/test/Result/SuccessTest.php @@ -23,7 +23,7 @@ public function testSuccess() public function testSuccessFromCheck() { - $check = $this->getMock(CheckInterface::class); + $check = $this->createMock(CheckInterface::class); $check ->expects($this->any()) ->method('getName') diff --git a/test/ResultAggregatorTest.php b/test/ResultAggregatorTest.php index 6f7f0089..334a9e4e 100644 --- a/test/ResultAggregatorTest.php +++ b/test/ResultAggregatorTest.php @@ -24,7 +24,7 @@ class ResultAggregatorTest extends PHPUnit_Framework_TestCase public function setUp() { - $this->check = $this->getMock(CheckInterface::class); + $this->check = $this->createMock(CheckInterface::class); $this->check ->expects($this->any()) ->method('getName') diff --git a/test/ResultRenderer/AbstractResultRendererTest.php b/test/ResultRenderer/AbstractResultRendererTest.php index 8c3932c5..f8f29b6a 100644 --- a/test/ResultRenderer/AbstractResultRendererTest.php +++ b/test/ResultRenderer/AbstractResultRendererTest.php @@ -30,11 +30,8 @@ protected function getRenderer() $color = new Color; $color->setForceStyle(true); - $this->terminal = $this->getMock(TerminalInterface::class); - $exerciseRepo = $this->getMockBuilder(ExerciseRepository::class) - ->disableOriginalConstructor() - ->getMock(); - + $this->terminal = $this->createMock(TerminalInterface::class); + $exerciseRepo = $this->createMock(ExerciseRepository::class); $this->terminal ->expects($this->any()) ->method('getWidth') diff --git a/test/ResultRenderer/CgiOutResultRendererTest.php b/test/ResultRenderer/CgiOutResultRendererTest.php index 6ddb47b5..542bdb90 100644 --- a/test/ResultRenderer/CgiOutResultRendererTest.php +++ b/test/ResultRenderer/CgiOutResultRendererTest.php @@ -25,7 +25,7 @@ class CgiOutResultRendererTest extends AbstractResultRendererTest public function testRenderWhenOnlyHeadersDifferent() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'OUTPUT', 'OUTPUT', ['header1' => 'val', 'header2' => 'val'], @@ -47,7 +47,7 @@ public function testRenderWhenOnlyHeadersDifferent() public function testRenderWhenOnlyOutputDifferent() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'EXPECTED OUTPUT', 'ACTUAL OUTPUT', ['header1' => 'val'], @@ -68,7 +68,7 @@ public function testRenderWhenOnlyOutputDifferent() public function testRenderWhenOutputAndHeadersDifferent() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'EXPECTED OUTPUT', 'ACTUAL OUTPUT', ['header1' => 'val', 'header2' => 'val'], @@ -93,7 +93,7 @@ public function testRenderWhenOutputAndHeadersDifferent() public function testNothingIsRenderedForSuccess() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'EXPECTED OUTPUT', 'ACTUAL OUTPUT', ['header1' => 'val', 'header2' => 'val'], @@ -118,7 +118,7 @@ public function testNothingIsRenderedForSuccess() public function testMultipleFailedRequests() { $failure1 = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'EXPECTED OUTPUT 1', 'ACTUAL OUTPUT 1', ['header1' => 'val', 'header2' => 'val'], @@ -126,7 +126,7 @@ public function testMultipleFailedRequests() ); $failure2 = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'EXPECTED OUTPUT 2', 'ACTUAL OUTPUT 2', ['header1' => 'val', 'header2' => 'val'], @@ -159,7 +159,7 @@ public function testMultipleFailedRequests() public function testCodeExecutionFailureIsDelegatedToMainRenderer() { $failure = new CgiOutRequestFailure( - $this->getMock(RequestInterface::class), + $this->createMock(RequestInterface::class), 'EXPECTED OUTPUT', 'ACTUAL OUTPUT', ['header1' => 'val', 'header2' => 'val'], diff --git a/test/ResultRenderer/FailureRendererTest.php b/test/ResultRenderer/FailureRendererTest.php index 35a7e665..f6026adf 100644 --- a/test/ResultRenderer/FailureRendererTest.php +++ b/test/ResultRenderer/FailureRendererTest.php @@ -18,7 +18,7 @@ class FailureRendererTest extends AbstractResultRendererTest { public function testRender() { - $failure = new Failure($this->getMock(CheckInterface::class), 'Something went wrong'); + $failure = new Failure($this->createMock(CheckInterface::class), 'Something went wrong'); $renderer = new FailureRenderer($failure); $this->assertEquals(" Something went wrong\n", $renderer->render($this->getRenderer())); } diff --git a/test/ResultRenderer/FunctionRequirementsFailureRendererTest.php b/test/ResultRenderer/FunctionRequirementsFailureRendererTest.php index 77ae210f..017fcd19 100644 --- a/test/ResultRenderer/FunctionRequirementsFailureRendererTest.php +++ b/test/ResultRenderer/FunctionRequirementsFailureRendererTest.php @@ -17,7 +17,7 @@ class FunctionRequirementsFailureRendererTest extends AbstractResultRendererTest public function testRenderer() { $failure = new FunctionRequirementsFailure( - $this->getMock(CheckInterface::class), + $this->createMock(CheckInterface::class), [['function' => 'file', 'line' => 3], ['function' => 'explode', 'line' => 5]], ['implode'] ); diff --git a/test/ResultRenderer/OutputFailureRendererTest.php b/test/ResultRenderer/OutputFailureRendererTest.php index 43fa4548..94aa3eed 100644 --- a/test/ResultRenderer/OutputFailureRendererTest.php +++ b/test/ResultRenderer/OutputFailureRendererTest.php @@ -17,7 +17,7 @@ class OutputFailureRendererTest extends AbstractResultRendererTest { public function testRender() { - $failure = new StdOutFailure($this->getMock(CheckInterface::class), 'EXPECTED OUTPUT', 'ACTUAL OUTPUT'); + $failure = new StdOutFailure($this->createMock(CheckInterface::class), 'EXPECTED OUTPUT', 'ACTUAL OUTPUT'); $renderer = new OutputFailureRenderer($failure); $expected = " ACTUAL\n"; diff --git a/test/ResultRenderer/ResultsRendererTest.php b/test/ResultRenderer/ResultsRendererTest.php index 05447ff6..f7533ee7 100644 --- a/test/ResultRenderer/ResultsRendererTest.php +++ b/test/ResultRenderer/ResultsRendererTest.php @@ -29,7 +29,7 @@ public function testRenderIndividualResult() $renderer = new ResultsRenderer( 'app', $color, - $this->getMock(TerminalInterface::class), + $this->createMock(TerminalInterface::class), new ExerciseRepository([]), (new Factory)->__invoke(), new ResultRendererFactory @@ -44,7 +44,7 @@ public function testLineBreak() $color = new Color; $color->setForceStyle(true); - $terminal = $this->getMock(TerminalInterface::class); + $terminal = $this->createMock(TerminalInterface::class); $terminal ->expects($this->once()) ->method('getWidth') diff --git a/test/Solution/DirectorySolutionTest.php b/test/Solution/DirectorySolutionTest.php index 54956b9e..aeee0e4e 100644 --- a/test/Solution/DirectorySolutionTest.php +++ b/test/Solution/DirectorySolutionTest.php @@ -20,10 +20,8 @@ public function testExceptionIsThrownIfEntryPointDoesNotExist() @mkdir($tempPath, 0775, true); touch(sprintf('%s/some-class.php', $tempPath)); - $this->setExpectedException( - InvalidArgumentException::class, - sprintf('Entry point: "solution.php" does not exist in: "%s"', $tempPath) - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf('Entry point: "solution.php" does not exist in: "%s"', $tempPath)); DirectorySolution::fromDirectory($tempPath); diff --git a/test/Solution/SolutionFileTest.php b/test/Solution/SolutionFileTest.php index aa6205d4..b5329e07 100644 --- a/test/Solution/SolutionFileTest.php +++ b/test/Solution/SolutionFileTest.php @@ -15,10 +15,8 @@ class SolutionFileTest extends PHPUnit_Framework_TestCase { public function testExceptionIsThrowIfFileNotExists() { - $this->setExpectedException( - InvalidArgumentException::class, - 'File: "file/that/does/not/exist.php" does not exist' - ); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('File: "file/that/does/not/exist.php" does not exist'); SolutionFile::fromFile('file/that/does/not/exist.php'); } diff --git a/test/UserStateSerializerTest.php b/test/UserStateSerializerTest.php index 9781ed19..0d907f67 100644 --- a/test/UserStateSerializerTest.php +++ b/test/UserStateSerializerTest.php @@ -191,8 +191,8 @@ public function testOldDataWillBeMigratedWhenInCorrectWorkshop() $oldSave = sprintf('%s/.phpschool.json', $this->tmpDir); $newSave = sprintf('%s/.phpschool-save.json', $this->tmpDir); - $e1 = $this->getMock(ExerciseInterface::class); - $e2 = $this->getMock(ExerciseInterface::class); + $e1 = $this->createMock(ExerciseInterface::class); + $e2 = $this->createMock(ExerciseInterface::class); $e1->expects($this->once())->method('getName')->willReturn('Exercise 1'); $e2->expects($this->once())->method('getName')->willReturn('Exercise 2'); @@ -230,8 +230,8 @@ public function testOldDataWillNotBeMigratedWhenNotInCorrectWorkshop() $oldSave = sprintf('%s/.phpschool.json', $this->tmpDir); $newSave = sprintf('%s/.phpschool-save.json', $this->tmpDir); - $e1 = $this->getMock(ExerciseInterface::class); - $e2 = $this->getMock(ExerciseInterface::class); + $e1 = $this->createMock(ExerciseInterface::class); + $e2 = $this->createMock(ExerciseInterface::class); $e1->expects($this->once())->method('getName')->willReturn('Exercise 1'); $e2->expects($this->once())->method('getName')->willReturn('Exercise 2'); @@ -264,8 +264,8 @@ public function testOldDataWillNotBeMigratedWhenNotInCorrectWorkshopWithOtherWor $oldSave = sprintf('%s/.phpschool.json', $this->tmpDir); $newSave = sprintf('%s/.phpschool-save.json', $this->tmpDir); - $e1 = $this->getMock(ExerciseInterface::class); - $e2 = $this->getMock(ExerciseInterface::class); + $e1 = $this->createMock(ExerciseInterface::class); + $e2 = $this->createMock(ExerciseInterface::class); $e1->expects($this->once())->method('getName')->willReturn('Exercise 1'); $e2->expects($this->once())->method('getName')->willReturn('Exercise 2'); From b93ec42326de6b4fb339cd3ea23f00b1f37efaaa Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Sun, 12 Jun 2016 22:39:45 +0200 Subject: [PATCH 2/2] Update PHPunit --- composer.json | 2 +- composer.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c18389db..f5a65107 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ }, "require-dev": { "composer/composer": "^1.0-alpha", - "phpunit/phpunit": "^5.1", + "phpunit/phpunit": "^5.4", "squizlabs/php_codesniffer": "^2.4" }, "autoload" : { diff --git a/composer.lock b/composer.lock index 1aebca7c..8698e2f9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "08918b48ed1afd53a4d8ee4f492e8b03", - "content-hash": "21f1705d07a93a8b7f249bd23a0755df", + "hash": "29079feccc0cab9039a34d0884ddb498", + "content-hash": "c69c183c2932a5171a4097073615c9d5", "packages": [ { "name": "aydin-hassan/cli-md-renderer",