Skip to content

Phpunit deprecations #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions test/Check/CheckRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -26,17 +26,17 @@ 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());
}

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)));
Expand All @@ -46,22 +46,20 @@ 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');
}

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)));
Expand Down
4 changes: 2 additions & 2 deletions test/Check/CodeParseCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testUnParseableCodeReturnsFailure()
{
file_put_contents($this->file, '<?php $lol');

$result = $this->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());
Expand All @@ -62,7 +62,7 @@ public function testParseableCodeReturnsSuccess()
{
file_put_contents($this->file, '<?php $lol = "lol";');

$result = $this->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());
Expand Down
6 changes: 3 additions & 3 deletions test/Check/ComposerCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}
Expand Down Expand Up @@ -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]));
Expand Down
4 changes: 2 additions & 2 deletions test/Check/DatabaseCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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)
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/Check/FileExistsCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions test/Check/FunctionRequirementsCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test/Check/PhpLintCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions test/CodeInsertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions test/CodePatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<?php\n\nini_set(\"display_errors\", 1);\n\$original = true;";
$this->assertEquals($expected, $patcher->patch($exercise, '<?php $original = true;'));
Expand All @@ -39,7 +39,7 @@ public function testDefaultPatchIsAppliedIfAvailable()
public function testPatcherDoesNotApplyPatchIfNotPatchableExercise()
{
$patcher = new CodePatcher((new ParserFactory)->create(ParserFactory::PREFER_PHP7), new Standard);
$exercise = $this->getMock(ExerciseInterface::class);
$exercise = $this->createMock(ExerciseInterface::class);

$code = '<?php $original = true;';
$this->assertEquals($code, $patcher->patch($exercise, $code));
Expand All @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions test/Command/CreditsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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
);

Expand All @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion test/Command/HelpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
16 changes: 8 additions & 8 deletions test/Command/MenuCommandInvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 1 addition & 4 deletions test/Command/MenuCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 5 additions & 13 deletions test/Command/PrintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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')
Expand All @@ -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())
Expand Down
Loading