From ab723af4078d0c7cee48c143eb1d037d6fb3ee4e Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Tue, 20 Nov 2018 07:59:35 +0300 Subject: [PATCH] Remove Mockery as dev dependency (#574) * Remove Mockery as dev dependency * add dockblock to cover phpstan, remove ignoreErrors from the phpstan config as no longer required * fix callback mock * fix callback call --- composer.json | 1 - composer.lock | 115 +--------- devTools/phpstan-tests.neon | 2 - phpunit.xml.dist | 5 - .../AbstractBaseProviderTest.php | 18 +- .../ValueProvider/ExcludeDirsProviderTest.php | 39 ++-- ...hpUnitCustomExecutablePathProviderTest.php | 67 +++--- .../ValueProvider/SourceDirsProviderTest.php | 93 ++++---- .../TestFrameworkConfigPathProviderTest.php | 120 ++++++---- .../ValueProvider/TextLogFileProviderTest.php | 31 ++- .../ValueProvider/TimeoutProviderTest.php | 41 ++-- tests/Console/LogVerbosityTest.php | 44 ++-- tests/Logger/BadgeLoggerTest.php | 103 +++++---- .../Generator/MutationsGeneratorTest.php | 99 +++++--- tests/Mutant/MetricsCalculatorTest.php | 14 +- tests/Mutant/MutantCreatorTest.php | 38 ++-- tests/Mutator/Util/MutatorsGeneratorTest.php | 34 ++- tests/Process/Builder/ProcessBuilderTest.php | 22 +- ...nitialTestsConsoleLoggerSubscriberTest.php | 38 ++-- tests/Process/MutantProcessTest.php | 214 +++++++++++------- .../Process/Runner/InitialTestsRunnerTest.php | 40 ++-- .../Parallel/ParallelProcessRunnerTest.php | 100 +++++--- .../CachedTestFileDataProviderTest.php | 12 +- .../Coverage/CodeCoverageDataTest.php | 20 +- tests/TestFramework/FactoryTest.php | 8 +- .../PhpSpec/Adapter/PhpSpecAdapterTest.php | 18 +- .../Builder/MutationConfigBuilderTest.php | 38 ++-- .../Builder/InitialConfigBuilderTest.php | 6 +- .../Builder/MutationConfigBuilderTest.php | 70 ++++-- 29 files changed, 761 insertions(+), 689 deletions(-) diff --git a/composer.json b/composer.json index a5c82f490..f2ca84f82 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,6 @@ "webmozart/assert": "^1.3" }, "require-dev": { - "mockery/mockery": "^1.1", "phpunit/phpunit": "^6" }, "bin": ["bin/infection"] diff --git a/composer.lock b/composer.lock index 0390649b7..d9af7a6bb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6136bf91d17bd67f560460694af046c0", + "content-hash": "f1e90f9b739e2ea6b8c0096d914fae17", "packages": [ { "name": "composer/ca-bundle", @@ -1146,119 +1146,6 @@ ], "time": "2017-07-22T11:58:36+00:00" }, - { - "name": "hamcrest/hamcrest-php", - "version": "v2.0.0", - "source": { - "type": "git", - "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/776503d3a8e85d4f9a1148614f95b7a608b046ad", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad", - "shasum": "" - }, - "require": { - "php": "^5.3|^7.0" - }, - "replace": { - "cordoval/hamcrest-php": "*", - "davedevelopment/hamcrest-php": "*", - "kodova/hamcrest-php": "*" - }, - "require-dev": { - "phpunit/php-file-iterator": "1.3.3", - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "hamcrest" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD" - ], - "description": "This is the PHP port of Hamcrest Matchers", - "keywords": [ - "test" - ], - "time": "2016-01-20T08:20:44+00:00" - }, - { - "name": "mockery/mockery", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/mockery/mockery.git", - "reference": "100633629bf76d57430b86b7098cd6beb996a35a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/100633629bf76d57430b86b7098cd6beb996a35a", - "reference": "100633629bf76d57430b86b7098cd6beb996a35a", - "shasum": "" - }, - "require": { - "hamcrest/hamcrest-php": "~2.0", - "lib-pcre": ">=7.0", - "php": ">=5.6.0" - }, - "require-dev": { - "phpunit/phpunit": "~5.7.10|~6.5|~7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Mockery": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Pádraic Brady", - "email": "padraic.brady@gmail.com", - "homepage": "http://blog.astrumfutura.com" - }, - { - "name": "Dave Marshall", - "email": "dave.marshall@atstsolutions.co.uk", - "homepage": "http://davedevelopment.co.uk" - } - ], - "description": "Mockery is a simple yet flexible PHP mock object framework", - "homepage": "https://github.com/mockery/mockery", - "keywords": [ - "BDD", - "TDD", - "library", - "mock", - "mock objects", - "mockery", - "stub", - "test", - "test double", - "testing" - ], - "time": "2018-10-02T21:52:37+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.8.1", diff --git a/devTools/phpstan-tests.neon b/devTools/phpstan-tests.neon index 4abb99322..b3827533f 100644 --- a/devTools/phpstan-tests.neon +++ b/devTools/phpstan-tests.neon @@ -1,5 +1,3 @@ parameters: excludes_analyse: - %currentWorkingDirectory%/tests/Fixtures/* - ignoreErrors: - - '#Call to an undefined method Mockery#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 52aa0ada6..cb3e714ad 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,14 +18,9 @@ - - - - large - diff --git a/tests/Config/ValueProvider/AbstractBaseProviderTest.php b/tests/Config/ValueProvider/AbstractBaseProviderTest.php index 1367a539b..deecf94c3 100644 --- a/tests/Config/ValueProvider/AbstractBaseProviderTest.php +++ b/tests/Config/ValueProvider/AbstractBaseProviderTest.php @@ -35,7 +35,7 @@ namespace Infection\Tests\Config\ValueProvider; -use Mockery; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\StreamableInputInterface; use Symfony\Component\Console\Output\StreamOutput; @@ -43,16 +43,16 @@ /** * @internal */ -abstract class AbstractBaseProviderTest extends Mockery\Adapter\Phpunit\MockeryTestCase +abstract class AbstractBaseProviderTest extends TestCase { protected static $stty; - protected function getQuestionHelper() + protected function getQuestionHelper(): QuestionHelper { return new QuestionHelper(); } - protected function getInputStream($input) + protected function getInputStream(string $input) { $stream = fopen('php://memory', 'r+b', false); fwrite($stream, $input); @@ -61,7 +61,7 @@ protected function getInputStream($input) return $stream; } - protected function createOutputInterface() + protected function createOutputInterface(): StreamOutput { return new StreamOutput(fopen('php://memory', 'r+b', false)); } @@ -69,20 +69,18 @@ protected function createOutputInterface() protected function createStreamableInputInterfaceMock($stream = null, $interactive = true) { $mock = $this->createMock(StreamableInputInterface::class); - $mock->expects($this->any()) - ->method('isInteractive') + $mock->method('isInteractive') ->will($this->returnValue($interactive)); if ($stream) { - $mock->expects($this->any()) - ->method('getStream') + $mock->method('getStream') ->willReturn($stream); } return $mock; } - protected function hasSttyAvailable() + protected function hasSttyAvailable(): bool { if (null !== self::$stty) { return self::$stty; diff --git a/tests/Config/ValueProvider/ExcludeDirsProviderTest.php b/tests/Config/ValueProvider/ExcludeDirsProviderTest.php index 329221c29..663ec756d 100644 --- a/tests/Config/ValueProvider/ExcludeDirsProviderTest.php +++ b/tests/Config/ValueProvider/ExcludeDirsProviderTest.php @@ -37,7 +37,6 @@ use Infection\Config\ConsoleHelper; use Infection\Config\ValueProvider\ExcludeDirsProvider; -use Mockery; use Symfony\Component\Filesystem\Filesystem; /** @@ -55,12 +54,23 @@ final class ExcludeDirsProviderTest extends AbstractBaseProviderTest */ private $fileSystem; + /** + * @var ExcludeDirsProvider + */ + private $provider; + protected function setUp(): void { $this->workspace = \sys_get_temp_dir() . '/exclude' . \microtime(true) . \random_int(100, 999); \mkdir($this->workspace, 0777, true); $this->fileSystem = new Filesystem(); + + $this->provider = new ExcludeDirsProvider( + $this->createMock(ConsoleHelper::class), + $this->getQuestionHelper(), + $this->fileSystem + ); } protected function tearDown(): void @@ -73,14 +83,7 @@ protected function tearDown(): void */ public function test_it_contains_vendors_when_sources_contains_current_dir(string $excludedRootDir, array $dirsInCurrentFolder): void { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $provider = new ExcludeDirsProvider($consoleMock, $dialog, $this->fileSystem); - - $excludedDirs = $provider->get( + $excludedDirs = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $this->createOutputInterface(), $dirsInCurrentFolder, @@ -96,14 +99,7 @@ public function test_it_validates_dirs(): void $this->markTestSkipped('Stty is not available'); } - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $provider = new ExcludeDirsProvider($consoleMock, $dialog, $this->fileSystem); - - $excludeDirs = $provider->get( + $excludeDirs = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("abc\n")), $this->createOutputInterface(), ['src'], @@ -125,14 +121,7 @@ public function test_passes_when_correct_dir_typed(): void \mkdir($dir1); \mkdir($dir2); - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $provider = new ExcludeDirsProvider($consoleMock, $dialog, $this->fileSystem); - - $excludeDirs = $provider->get( + $excludeDirs = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("foo\n")), $this->createOutputInterface(), ['src'], diff --git a/tests/Config/ValueProvider/PhpUnitCustomExecutablePathProviderTest.php b/tests/Config/ValueProvider/PhpUnitCustomExecutablePathProviderTest.php index 26c6e281a..b0a34d33b 100644 --- a/tests/Config/ValueProvider/PhpUnitCustomExecutablePathProviderTest.php +++ b/tests/Config/ValueProvider/PhpUnitCustomExecutablePathProviderTest.php @@ -39,7 +39,7 @@ use Infection\Config\ValueProvider\PhpUnitCustomExecutablePathProvider; use Infection\Finder\Exception\FinderException; use Infection\Finder\TestFrameworkFinder; -use Mockery; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Exception\RuntimeException as SymfonyRuntimeException; use function Infection\Tests\normalizePath as p; @@ -48,39 +48,48 @@ */ final class PhpUnitCustomExecutablePathProviderTest extends AbstractBaseProviderTest { - public function test_it_returns_null_if_executable_is_found(): void + /** + * @var MockObject|TestFrameworkFinder + */ + private $finderMock; + + /** + * @var PhpUnitCustomExecutablePathProvider + */ + private $provider; + + protected function setUp(): void { - $finderMock = Mockery::mock(TestFrameworkFinder::class); - $finderMock->shouldReceive('find')->once(); + $this->finderMock = $this->createMock(TestFrameworkFinder::class); - $provider = new PhpUnitCustomExecutablePathProvider( - $finderMock, + $this->provider = new PhpUnitCustomExecutablePathProvider( + $this->finderMock, $this->createMock(ConsoleHelper::class), $this->getQuestionHelper() ); + } - $result = $provider->get($this->createStreamableInputInterfaceMock(), $this->createOutputInterface()); + public function test_it_returns_null_if_executable_is_found(): void + { + $this->finderMock + ->expects($this->once()) + ->method('find'); - $this->assertNull($result); + $this->assertNull( + $this->provider->get($this->createStreamableInputInterfaceMock(), $this->createOutputInterface()) + ); } public function test_it_asks_question_if_no_config_is_found_in_current_dir(): void { - $finderMock = Mockery::mock(TestFrameworkFinder::class); - $finderMock->shouldReceive('find')->once()->andThrow(new FinderException()); - - $consoleMock = $this->createMock(ConsoleHelper::class); - $consoleMock->expects($this->once())->method('getQuestion')->willReturn('foobar'); - - $provider = new PhpUnitCustomExecutablePathProvider( - $finderMock, - $consoleMock, - $this->getQuestionHelper() - ); + $this->finderMock + ->expects($this->once()) + ->method('find') + ->will($this->throwException(new FinderException())); $customExecutable = p(realpath(__DIR__ . '/../../Fixtures/Files/phpunit/phpunit.phar')); - $path = $provider->get( + $path = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("{$customExecutable}\n")), $this->createOutputInterface() ); @@ -94,22 +103,14 @@ public function test_validates_incorrect_dir(): void $this->markTestSkipped('Stty is not available'); } - $finderMock = Mockery::mock(TestFrameworkFinder::class); - - $finderMock->shouldReceive('find')->once()->andThrow(new FinderException()); - - $consoleMock = $this->createMock(ConsoleHelper::class); - $consoleMock->expects($this->once())->method('getQuestion')->willReturn('foobar'); - - $provider = new PhpUnitCustomExecutablePathProvider( - $finderMock, - $consoleMock, - $this->getQuestionHelper() - ); + $this->finderMock + ->expects($this->once()) + ->method('find') + ->will($this->throwException(new FinderException())); $this->expectException(SymfonyRuntimeException::class); - $provider->get( + $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("abc\n")), $this->createOutputInterface() ); diff --git a/tests/Config/ValueProvider/SourceDirsProviderTest.php b/tests/Config/ValueProvider/SourceDirsProviderTest.php index 4af17b721..791490a7a 100644 --- a/tests/Config/ValueProvider/SourceDirsProviderTest.php +++ b/tests/Config/ValueProvider/SourceDirsProviderTest.php @@ -38,30 +38,45 @@ use Infection\Config\ConsoleHelper; use Infection\Config\Guesser\SourceDirGuesser; use Infection\Config\ValueProvider\SourceDirsProvider; -use Mockery; +use PHPUnit\Framework\MockObject\MockObject; /** * @internal */ final class SourceDirsProviderTest extends AbstractBaseProviderTest { + /** + * @var SourceDirsProvider + */ + private $provider; + + /** + * @var MockObject|SourceDirGuesser + */ + private $sourceDirGuesser; + + protected function setUp(): void + { + $this->sourceDirGuesser = $this->createMock(SourceDirGuesser::class); + + $this->provider = new SourceDirsProvider( + $this->createMock(ConsoleHelper::class), + $this->getQuestionHelper(), + $this->sourceDirGuesser + ); + } + public function test_it_uses_guesser_and_default_value(): void { if (stripos(PHP_OS, 'WIN') === 0) { $this->markTestSkipped('Stty is not available'); } - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $sourceDirGuesser = $this->createMock(SourceDirGuesser::class); - $sourceDirGuesser->method('guess')->willReturn(['src']); + $this->sourceDirGuesser + ->method('guess') + ->willReturn(['src']); - $provider = new SourceDirsProvider($consoleMock, $dialog, $sourceDirGuesser); - - $sourceDirs = $provider->get( + $sourceDirs = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $this->createOutputInterface(), ['src'] @@ -72,17 +87,11 @@ public function test_it_uses_guesser_and_default_value(): void public function test_it_uses_guesser_and_non_default_guessed_value(): void { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); + $this->sourceDirGuesser + ->method('guess') + ->willReturn(['src/Namespace']); - $sourceDirGuesser = $this->createMock(SourceDirGuesser::class); - $sourceDirGuesser->method('guess')->willReturn(['src/Namespace']); - - $provider = new SourceDirsProvider($consoleMock, $dialog, $sourceDirGuesser); - - $sourceDirs = $provider->get( + $sourceDirs = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $this->createOutputInterface(), ['src'] @@ -93,17 +102,11 @@ public function test_it_uses_guesser_and_non_default_guessed_value(): void public function test_it_uses_guesser_and_multiple_guessed_dirs(): void { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); + $this->sourceDirGuesser + ->method('guess') + ->willReturn(['foo', 'bar']); - $sourceDirGuesser = $this->createMock(SourceDirGuesser::class); - $sourceDirGuesser->method('guess')->willReturn(['foo', 'bar']); - - $provider = new SourceDirsProvider($consoleMock, $dialog, $sourceDirGuesser); - - $sourceDirs = $provider->get( + $sourceDirs = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $this->createOutputInterface(), ['src'] @@ -114,17 +117,11 @@ public function test_it_uses_guesser_and_multiple_guessed_dirs(): void public function test_it_fills_choices_with_current_dir(): void { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); + $this->sourceDirGuesser + ->method('guess') + ->willReturn(['src']); - $sourceDirGuesser = $this->createMock(SourceDirGuesser::class); - $sourceDirGuesser->method('guess')->willReturn(['src']); - - $provider = new SourceDirsProvider($consoleMock, $dialog, $sourceDirGuesser); - - $sourceDirs = $provider->get( + $sourceDirs = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("0\n")), $this->createOutputInterface(), ['src'] @@ -135,19 +132,13 @@ public function test_it_fills_choices_with_current_dir(): void public function test_it_throws_exception_when_current_dir_is_selected_with_another_dir(): void { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $sourceDirGuesser = $this->createMock(SourceDirGuesser::class); - $sourceDirGuesser->method('guess')->willReturn(['src']); - - $provider = new SourceDirsProvider($consoleMock, $dialog, $sourceDirGuesser); + $this->sourceDirGuesser + ->method('guess') + ->willReturn(['src']); $this->expectException(\LogicException::class); - $provider->get( + $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("0,1\n")), $this->createOutputInterface(), ['src'] diff --git a/tests/Config/ValueProvider/TestFrameworkConfigPathProviderTest.php b/tests/Config/ValueProvider/TestFrameworkConfigPathProviderTest.php index 96460ed91..0816d0508 100644 --- a/tests/Config/ValueProvider/TestFrameworkConfigPathProviderTest.php +++ b/tests/Config/ValueProvider/TestFrameworkConfigPathProviderTest.php @@ -38,7 +38,7 @@ use Infection\Config\ConsoleHelper; use Infection\Config\ValueProvider\TestFrameworkConfigPathProvider; use Infection\TestFramework\Config\TestFrameworkConfigLocatorInterface; -use Mockery; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -47,18 +47,39 @@ */ final class TestFrameworkConfigPathProviderTest extends AbstractBaseProviderTest { - public function test_it_calls_locator_in_the_current_dir(): void + /** + * @var TestFrameworkConfigPathProvider + */ + private $provider; + + /** + * @var MockObject|TestFrameworkConfigLocatorInterface + */ + private $locatorMock; + + /** + * @var MockObject|ConsoleHelper + */ + private $consoleMock; + + protected function setUp(): void { - $locatorMock = $this->createMock(TestFrameworkConfigLocatorInterface::class); - $locatorMock->expects($this->once())->method('locate'); - - $provider = new TestFrameworkConfigPathProvider( - $locatorMock, - $this->createMock(ConsoleHelper::class), + $this->locatorMock = $this->createMock(TestFrameworkConfigLocatorInterface::class); + $this->consoleMock = $this->createMock(ConsoleHelper::class); + $this->provider = new TestFrameworkConfigPathProvider( + $this->locatorMock, + $this->consoleMock, $this->getQuestionHelper() ); + } - $result = $provider->get( + public function test_it_calls_locator_in_the_current_dir(): void + { + $this->locatorMock + ->expects($this->once()) + ->method('locate'); + + $result = $this->provider->get( $this->createStreamableInputInterfaceMock(), $this->createOutputInterface(), [], @@ -70,20 +91,25 @@ public function test_it_calls_locator_in_the_current_dir(): void public function test_it_asks_question_if_no_config_is_found_in_current_dir(): void { - $locatorMock = Mockery::mock(TestFrameworkConfigLocatorInterface::class); - - $locatorMock->shouldReceive('locate')->once()->andThrow(new \Exception()); - $locatorMock->shouldReceive('locate')->once()->andThrow(new \Exception()); - $locatorMock->shouldReceive('locate')->once()->andReturn(true); - - $consoleMock = $this->createMock(ConsoleHelper::class); - $consoleMock->expects($this->once())->method('getQuestion')->willReturn('foobar'); - - $provider = new TestFrameworkConfigPathProvider($locatorMock, $consoleMock, $this->getQuestionHelper()); + $this->consoleMock + ->expects($this->once()) + ->method('getQuestion') + ->willReturn('foobar'); + + $this->locatorMock + ->expects($this->exactly(3)) + ->method('locate') + ->will( + $this->onConsecutiveCalls( + $this->throwException(new \Exception()), + $this->throwException(new \Exception()), + true + ) + ); $inputPhpUnitPath = realpath(__DIR__ . '/../../Fixtures/Files/phpunit'); - $path = $provider->get( + $path = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("{$inputPhpUnitPath}\n")), $this->createOutputInterface(), [], @@ -96,19 +122,23 @@ public function test_it_asks_question_if_no_config_is_found_in_current_dir(): vo public function test_it_automatically_guesses_path(): void { - $locatorMock = Mockery::mock(TestFrameworkConfigLocatorInterface::class); - - $locatorMock->shouldReceive('locate')->once()->andThrow(new \Exception()); - $locatorMock->shouldReceive('locate')->once()->andReturn(true); - - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->never(); - - $provider = new TestFrameworkConfigPathProvider($locatorMock, $consoleMock, $this->getQuestionHelper()); - - $path = $provider->get( - Mockery::mock(InputInterface::class), - Mockery::mock(OutputInterface::class), + $this->locatorMock + ->expects($this->exactly(2)) + ->method('locate') + ->will( + $this->onConsecutiveCalls( + $this->throwException(new \Exception()), + true + ) + ); + + $this->consoleMock + ->expects($this->never()) + ->method('getQuestion'); + + $path = $this->provider->get( + $this->createMock(InputInterface::class), + $this->createMock(OutputInterface::class), [], 'phpunit' ); @@ -122,18 +152,18 @@ public function test_validates_incorrect_dir(): void $this->markTestSkipped('Stty is not available'); } - $locatorMock = Mockery::mock(TestFrameworkConfigLocatorInterface::class); - - $locatorMock->shouldReceive('locate')->once()->andThrow(new \Exception()); - $locatorMock->shouldReceive('locate')->once()->andThrow(new \Exception()); - $locatorMock->shouldReceive('locate')->once()->andReturn(true); - - $consoleMock = $this->createMock(ConsoleHelper::class); - $consoleMock->expects($this->once())->method('getQuestion')->willReturn('foobar'); - - $provider = new TestFrameworkConfigPathProvider($locatorMock, $consoleMock, $this->getQuestionHelper()); - - $path = $provider->get( + $this->locatorMock + ->expects($this->exactly(3)) + ->method('locate') + ->will( + $this->onConsecutiveCalls( + $this->throwException(new \Exception()), + $this->throwException(new \Exception()), + true + ) + ); + + $path = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("abc\n")), $this->createOutputInterface(), [], diff --git a/tests/Config/ValueProvider/TextLogFileProviderTest.php b/tests/Config/ValueProvider/TextLogFileProviderTest.php index fae4b5dcd..be459f540 100644 --- a/tests/Config/ValueProvider/TextLogFileProviderTest.php +++ b/tests/Config/ValueProvider/TextLogFileProviderTest.php @@ -37,23 +37,28 @@ use Infection\Config\ConsoleHelper; use Infection\Config\ValueProvider\TextLogFileProvider; -use Mockery; /** * @internal */ final class TextLogFileProviderTest extends AbstractBaseProviderTest { - public function test_it_uses_default_value(): void - { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); + /** + * @var TextLogFileProvider + */ + private $provider; - $provider = new TextLogFileProvider($consoleMock, $dialog); + protected function setUp(): void + { + $this->provider = new TextLogFileProvider( + $this->createMock(ConsoleHelper::class), + $this->getQuestionHelper() + ); + } - $textLogFilePath = $provider->get( + public function test_it_uses_default_value(): void + { + $textLogFilePath = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $this->createOutputInterface(), [] @@ -65,14 +70,8 @@ public function test_it_uses_default_value(): void public function test_it_uses_typed_value(): void { $inputValue = 'test-log.txt'; - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $provider = new TextLogFileProvider($consoleMock, $dialog); - $textLogFilePath = $provider->get( + $textLogFilePath = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("{$inputValue}\n")), $this->createOutputInterface(), [] diff --git a/tests/Config/ValueProvider/TimeoutProviderTest.php b/tests/Config/ValueProvider/TimeoutProviderTest.php index f070c71ce..3d3bc90d4 100644 --- a/tests/Config/ValueProvider/TimeoutProviderTest.php +++ b/tests/Config/ValueProvider/TimeoutProviderTest.php @@ -38,23 +38,28 @@ use Infection\Config\ConsoleHelper; use Infection\Config\InfectionConfig; use Infection\Config\ValueProvider\TimeoutProvider; -use Mockery; /** * @internal */ final class TimeoutProviderTest extends AbstractBaseProviderTest { - public function test_it_uses_default_value(): void - { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); + /** + * @var TimeoutProvider + */ + private $provider; - $provider = new TimeoutProvider($consoleMock, $dialog); + protected function setUp(): void + { + $this->provider = new TimeoutProvider( + $this->createMock(ConsoleHelper::class), + $this->getQuestionHelper() + ); + } - $timeout = $provider->get( + public function test_it_uses_default_value(): void + { + $timeout = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $this->createOutputInterface() ); @@ -64,14 +69,7 @@ public function test_it_uses_default_value(): void public function test_it_casts_any_value_to_integer(): void { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $provider = new TimeoutProvider($consoleMock, $dialog); - - $timeout = $provider->get( + $timeout = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("13\n")), $this->createOutputInterface() ); @@ -84,16 +82,9 @@ public function test_it_casts_any_value_to_integer(): void */ public function test_it_does_not_allow_invalid_values($inputValue): void { - $consoleMock = Mockery::mock(ConsoleHelper::class); - $consoleMock->shouldReceive('getQuestion')->once()->andReturn('?'); - - $dialog = $this->getQuestionHelper(); - - $provider = new TimeoutProvider($consoleMock, $dialog); - $this->expectException(\RuntimeException::class); - $timeout = $provider->get( + $timeout = $this->provider->get( $this->createStreamableInputInterfaceMock($this->getInputStream("{$inputValue}\n")), $this->createOutputInterface() ); diff --git a/tests/Console/LogVerbosityTest.php b/tests/Console/LogVerbosityTest.php index 2d5ddd402..829ec33bc 100644 --- a/tests/Console/LogVerbosityTest.php +++ b/tests/Console/LogVerbosityTest.php @@ -37,21 +37,21 @@ use Infection\Console\ConsoleOutput; use Infection\Console\LogVerbosity; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Style\SymfonyStyle; /** * @internal */ -final class LogVerbosityTest extends MockeryTestCase +final class LogVerbosityTest extends TestCase { public function test_it_works_if_verbosity_is_valid(): void { $input = $this->setInputExpectationsWhenItDoesNotChange(LogVerbosity::NORMAL); - LogVerbosity::convertVerbosityLevel($input, new ConsoleOutput(Mockery::mock(SymfonyStyle::class))); + LogVerbosity::convertVerbosityLevel($input, new ConsoleOutput($this->createMock(SymfonyStyle::class))); } /** @@ -60,10 +60,10 @@ public function test_it_works_if_verbosity_is_valid(): void public function test_it_converts_int_version_to_string_version_of_verbosity(int $input, string $output): void { $input = $this->setInputExpectationsWhenItDoesChange($input, $output); - $io = Mockery::mock(SymfonyStyle::class); - $io->shouldReceive('note') - ->withArgs(['Numeric versions of log-verbosity have been deprecated, please use, ' . $output . ' to keep the same result']) - ->once(); + $io = $this->createMock(SymfonyStyle::class); + $io->expects($this->once()) + ->method('note') + ->with('Numeric versions of log-verbosity have been deprecated, please use, ' . $output . ' to keep the same result'); LogVerbosity::convertVerbosityLevel($input, new ConsoleOutput($io)); } @@ -94,10 +94,10 @@ public function provideConvertedLogVerbosity() public function test_it_converts_to_normal_and_writes_notice_when_invalid_verbosity(): void { $input = $this->setInputExpectationsWhenItDoesChange('asdf', LogVerbosity::NORMAL); - $io = Mockery::mock(SymfonyStyle::class); - $io->shouldReceive('note') - ->withArgs(['Running infection with an unknown log-verbosity option, falling back to default option']) - ->once(); + $io = $this->createMock(SymfonyStyle::class); + $io->expects($this->once()) + ->method('note') + ->with('Running infection with an unknown log-verbosity option, falling back to default option'); LogVerbosity::convertVerbosityLevel($input, new ConsoleOutput($io)); } @@ -105,15 +105,15 @@ public function test_it_converts_to_normal_and_writes_notice_when_invalid_verbos /** * @param string|int $inputVerbosity * - * @return InputInterface|Mockery\MockInterface + * @return InputInterface|MockObject */ private function setInputExpectationsWhenItDoesNotChange($inputVerbosity) { - $input = Mockery::mock(InputInterface::class); - $input->shouldReceive('getOption') - ->withArgs(['log-verbosity']) - ->once() - ->andReturn($inputVerbosity); + $input = $this->createMock(InputInterface::class); + $input->expects($this->once()) + ->method('getOption') + ->with('log-verbosity') + ->willReturn($inputVerbosity); return $input; } @@ -121,14 +121,14 @@ private function setInputExpectationsWhenItDoesNotChange($inputVerbosity) /** * @param string|int $input * - * @return InputInterface|Mockery\MockInterface + * @return InputInterface|MockObject */ private function setInputExpectationsWhenItDoesChange($input, string $output) { $input = $this->setInputExpectationsWhenItDoesNotChange($input); - $input->shouldReceive('setOption') - ->withArgs(['log-verbosity', $output]) - ->once(); + $input->expects($this->once()) + ->method('setOption') + ->with('log-verbosity', $output); return $input; } diff --git a/tests/Logger/BadgeLoggerTest.php b/tests/Logger/BadgeLoggerTest.php index 44d291c36..cfd45a606 100644 --- a/tests/Logger/BadgeLoggerTest.php +++ b/tests/Logger/BadgeLoggerTest.php @@ -38,27 +38,27 @@ use Infection\Http\BadgeApiClient; use Infection\Logger\BadgeLogger; use Infection\Mutant\MetricsCalculator; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; /** * @internal */ -final class BadgeLoggerTest extends MockeryTestCase +final class BadgeLoggerTest extends TestCase { /** - * @var OutputInterface|Mockery\MockInterface + * @var OutputInterface|MockObject */ private $output; /** - * @var BadgeApiClient|Mockery\MockInterface + * @var BadgeApiClient|MockObject */ private $badgeApiClient; /** - * @var MetricsCalculator|Mockery\MockInterface + * @var MetricsCalculator|MockObject */ private $metricsCalculator; @@ -100,9 +100,9 @@ public static function tearDownAfterClass(): void protected function setUp(): void { - $this->output = Mockery::mock(OutputInterface::class); - $this->badgeApiClient = Mockery::mock(BadgeApiClient::class); - $this->metricsCalculator = Mockery::mock(MetricsCalculator::class); + $this->output = $this->createMock(OutputInterface::class); + $this->badgeApiClient = $this->createMock(BadgeApiClient::class); + $this->metricsCalculator = $this->createMock(MetricsCalculator::class); $config = new \stdClass(); $config->branch = 'master'; @@ -118,9 +118,12 @@ public function test_it_skips_logging_when_it_is_not_travis(): void { putenv('TRAVIS'); $this->output - ->shouldReceive('writeln') - ->withArgs(['Dashboard report has not been sent: it is not a Travis CI']); - $this->badgeApiClient->shouldReceive('sendReport')->never(); + ->method('writeln') + ->with('Dashboard report has not been sent: it is not a Travis CI'); + + $this->badgeApiClient + ->expects($this->never()) + ->method('sendReport'); $this->badgeLogger->log(); } @@ -130,9 +133,12 @@ public function test_it_skips_logging_when_it_is_pull_request(): void putenv('TRAVIS=true'); putenv('TRAVIS_PULL_REQUEST=123'); $this->output - ->shouldReceive('writeln') - ->withArgs(['Dashboard report has not been sent: build is for a pull request (TRAVIS_PULL_REQUEST=123)']); - $this->badgeApiClient->shouldReceive('sendReport')->never(); + ->method('writeln') + ->with('Dashboard report has not been sent: build is for a pull request (TRAVIS_PULL_REQUEST=123)'); + + $this->badgeApiClient + ->expects($this->never()) + ->method('sendReport'); $this->badgeLogger->log(); } @@ -145,9 +151,12 @@ public function test_it_skips_logging_when_branch_not_found(): void putenv('TRAVIS_BRANCH'); $this->output - ->shouldReceive('writeln') - ->withArgs(['Dashboard report has not been sent: repository slug nor current branch were found; not a Travis build?']); - $this->badgeApiClient->shouldReceive('sendReport')->never(); + ->method('writeln') + ->with('Dashboard report has not been sent: repository slug nor current branch were found; not a Travis build?'); + + $this->badgeApiClient + ->expects($this->never()) + ->method('sendReport'); $this->badgeLogger->log(); } @@ -160,9 +169,12 @@ public function test_it_skips_logging_when_repo_slug_not_found(): void putenv('TRAVIS_BRANCH=foo'); $this->output - ->shouldReceive('writeln') - ->withArgs(['Dashboard report has not been sent: repository slug nor current branch were found; not a Travis build?']); - $this->badgeApiClient->shouldReceive('sendReport')->never(); + ->method('writeln') + ->with('Dashboard report has not been sent: repository slug nor current branch were found; not a Travis build?'); + + $this->badgeApiClient + ->expects($this->never()) + ->method('sendReport'); $this->badgeLogger->log(); } @@ -174,9 +186,12 @@ public function test_it_skips_logging_when_it_is_branch_not_from_config(): void putenv('TRAVIS_REPO_SLUG=a/b'); putenv('TRAVIS_BRANCH=foo'); $this->output - ->shouldReceive('writeln') - ->withArgs(['Dashboard report has not been sent: expected branch "master", found "foo"']); - $this->badgeApiClient->shouldReceive('sendReport')->never(); + ->method('writeln') + ->with('Dashboard report has not been sent: expected branch "master", found "foo"'); + + $this->badgeApiClient + ->expects($this->never()) + ->method('sendReport'); $this->badgeLogger->log(); } @@ -192,9 +207,12 @@ public function test_it_sends_report_missing_our_api_key(): void putenv(BadgeLogger::ENV_STRYKER_DASHBOARD_API_KEY); $this->output - ->shouldReceive('writeln') - ->withArgs(['Dashboard report has not been sent: neither INFECTION_BADGE_API_KEY nor STRYKER_DASHBOARD_API_KEY were found in the environment']); - $this->badgeApiClient->shouldReceive('sendReport')->never(); + ->method('writeln') + ->with('Dashboard report has not been sent: neither INFECTION_BADGE_API_KEY nor STRYKER_DASHBOARD_API_KEY were found in the environment'); + + $this->badgeApiClient + ->expects($this->never()) + ->method('sendReport'); $this->badgeLogger->log(); } @@ -208,15 +226,17 @@ public function test_it_sends_report_when_everything_is_ok_with_stryker_key(): v putenv('TRAVIS_BRANCH=master'); $this->output - ->shouldReceive('writeln') - ->withArgs(['Sending dashboard report...']); + ->method('writeln') + ->with('Sending dashboard report...'); + $this->badgeApiClient - ->shouldReceive('sendReport') - ->once() - ->withArgs(['abc', 'github.com/a/b', 'master', 33.3]); + ->expects($this->once()) + ->method('sendReport') + ->with('abc', 'github.com/a/b', 'master', 33.3); + $this->metricsCalculator - ->shouldReceive('getMutationScoreIndicator') - ->andReturn(33.3); + ->method('getMutationScoreIndicator') + ->willReturn(33.3); $this->badgeLogger->log(); } @@ -230,16 +250,17 @@ public function test_it_sends_report_when_everything_is_ok_with_our_key(): void putenv('TRAVIS_BRANCH=master'); $this->output - ->shouldReceive('writeln') - ->withArgs(['Sending dashboard report...']); + ->method('writeln') + ->with('Sending dashboard report...'); $this->badgeApiClient - ->shouldReceive('sendReport') - ->once() - ->withArgs(['abc', 'github.com/a/b', 'master', 33.3]); + ->expects($this->once()) + ->method('sendReport') + ->with('abc', 'github.com/a/b', 'master', 33.3); + $this->metricsCalculator - ->shouldReceive('getMutationScoreIndicator') - ->andReturn(33.3); + ->method('getMutationScoreIndicator') + ->willReturn(33.3); $this->badgeLogger->log(); } diff --git a/tests/Mutant/Generator/MutationsGeneratorTest.php b/tests/Mutant/Generator/MutationsGeneratorTest.php index 530608c81..390f8a084 100644 --- a/tests/Mutant/Generator/MutationsGeneratorTest.php +++ b/tests/Mutant/Generator/MutationsGeneratorTest.php @@ -48,39 +48,47 @@ use Infection\TestFramework\Coverage\CodeCoverageData; use Infection\Tests\Fixtures\Files\Mutation\OneFile\OneFile; use Infection\WrongMutator\ErrorMutator; -use Mockery; use PhpParser\Lexer; use PhpParser\Parser; use PhpParser\ParserFactory; +use PHPUnit\Framework\TestCase; use Pimple\Container; /** * @internal */ -final class MutationsGeneratorTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class MutationsGeneratorTest extends TestCase { public function test_it_collects_plus_mutation(): void { - $codeCoverageDataMock = Mockery::mock(CodeCoverageData::class); - $codeCoverageDataMock->shouldReceive('hasTestsOnLine')->twice()->andReturn(true); - $codeCoverageDataMock->shouldReceive('hasExecutedMethodOnLine')->times(3)->andReturn(false); + $codeCoverageDataMock = $this->createMock(CodeCoverageData::class); - $generator = $this->createMutationGenerator($codeCoverageDataMock); + $codeCoverageDataMock->expects($this->exactly(2)) + ->method('hasTestsOnLine') + ->willReturn(true); - $mutations = $generator->generate(false); + $codeCoverageDataMock->expects($this->exactly(3)) + ->method('hasExecutedMethodOnLine') + ->willReturn(false); + + $mutations = $this->createMutationGenerator($codeCoverageDataMock)->generate(false); $this->assertInstanceOf(Plus::class, $mutations[3]->getMutator()); } public function test_it_collects_public_visibility_mutation(): void { - $codeCoverageDataMock = Mockery::mock(CodeCoverageData::class); - $codeCoverageDataMock->shouldReceive('hasTestsOnLine')->twice()->andReturn(true); - $codeCoverageDataMock->shouldReceive('hasExecutedMethodOnLine')->times(3)->andReturn(true); + $codeCoverageDataMock = $this->createMock(CodeCoverageData::class); - $generator = $this->createMutationGenerator($codeCoverageDataMock); + $codeCoverageDataMock->expects($this->exactly(2)) + ->method('hasTestsOnLine') + ->willReturn(true); - $mutations = $generator->generate(false); + $codeCoverageDataMock->expects($this->exactly(3)) + ->method('hasExecutedMethodOnLine') + ->willReturn(true); + + $mutations = $this->createMutationGenerator($codeCoverageDataMock)->generate(false); $this->assertInstanceOf(Plus::class, $mutations[3]->getMutator()); $this->assertInstanceOf(PublicVisibility::class, $mutations[4]->getMutator()); @@ -88,26 +96,34 @@ public function test_it_collects_public_visibility_mutation(): void public function test_it_can_skip_not_covered_on_file_level(): void { - $codeCoverageDataMock = Mockery::mock(CodeCoverageData::class); - $codeCoverageDataMock->shouldReceive('hasTests')->once()->andReturn(false); + $codeCoverageDataMock = $this->createMock(CodeCoverageData::class); - $generator = $this->createMutationGenerator($codeCoverageDataMock); + $codeCoverageDataMock->expects($this->once()) + ->method('hasTests') + ->willReturn(false); - $mutations = $generator->generate(true); + $mutations = $this->createMutationGenerator($codeCoverageDataMock)->generate(true); $this->assertCount(0, $mutations); } public function test_it_can_skip_not_covered_on_file_line_level(): void { - $codeCoverageDataMock = Mockery::mock(CodeCoverageData::class); - $codeCoverageDataMock->shouldReceive('hasTests')->once()->andReturn(true); - $codeCoverageDataMock->shouldReceive('hasTestsOnLine')->times(4)->andReturn(false); - $codeCoverageDataMock->shouldReceive('hasExecutedMethodOnLine')->times(3)->andReturn(true); + $codeCoverageDataMock = $this->createMock(CodeCoverageData::class); - $generator = $this->createMutationGenerator($codeCoverageDataMock); + $codeCoverageDataMock->expects($this->once()) + ->method('hasTests') + ->willReturn(true); - $mutations = $generator->generate(true); + $codeCoverageDataMock->expects($this->exactly(4)) + ->method('hasTestsOnLine') + ->willReturn(false); + + $codeCoverageDataMock->expects($this->exactly(3)) + ->method('hasExecutedMethodOnLine') + ->willReturn(true); + + $mutations = $this->createMutationGenerator($codeCoverageDataMock)->generate(true); $this->assertCount(3, $mutations); $this->assertInstanceOf(TrueValue::class, $mutations[0]->getMutator()); @@ -116,22 +132,32 @@ public function test_it_can_skip_not_covered_on_file_line_level(): void public function test_it_can_skip_not_covered_on_file_line_for_visibility(): void { - $codeCoverageDataMock = Mockery::mock(CodeCoverageData::class); - $codeCoverageDataMock->shouldReceive('hasTests')->once()->andReturn(true); - $codeCoverageDataMock->shouldReceive('hasTestsOnLine')->times(4)->andReturn(false); - $codeCoverageDataMock->shouldReceive('hasExecutedMethodOnLine')->times(3)->andReturn(false); + $codeCoverageDataMock = $this->createMock(CodeCoverageData::class); - $generator = $this->createMutationGenerator($codeCoverageDataMock); + $codeCoverageDataMock->expects($this->once()) + ->method('hasTests') + ->willReturn(true); - $mutations = $generator->generate(true); + $codeCoverageDataMock->expects($this->exactly(4)) + ->method('hasTestsOnLine') + ->willReturn(false); + + $codeCoverageDataMock->expects($this->exactly(3)) + ->method('hasExecutedMethodOnLine') + ->willReturn(false); + + $mutations = $this->createMutationGenerator($codeCoverageDataMock)->generate(true); $this->assertCount(0, $mutations); } public function test_it_can_skip_ignored_classes(): void { - $codeCoverageDataMock = Mockery::mock(CodeCoverageData::class); - $codeCoverageDataMock->shouldReceive('hasTests')->once()->andReturn(true); + $codeCoverageDataMock = $this->createMock(CodeCoverageData::class); + + $codeCoverageDataMock->expects($this->once()) + ->method('hasTests') + ->willReturn(true); $generator = $this->createMutationGenerator($codeCoverageDataMock, null, new MutatorConfig([ 'ignore' => [ @@ -146,9 +172,10 @@ public function test_it_can_skip_ignored_classes(): void public function test_it_executes_only_whitelisted_mutators(): void { - $codeCoverageDataMock = Mockery::mock(CodeCoverageData::class); - - $generator = $this->createMutationGenerator($codeCoverageDataMock, Decrement::class); + $generator = $this->createMutationGenerator( + $this->createMock(CodeCoverageData::class), + Decrement::class + ); $mutations = $generator->generate(false); @@ -158,7 +185,7 @@ public function test_it_executes_only_whitelisted_mutators(): void public function test_it_throws_correct_error_when_file_is_invalid(): void { $generator = $this->createMutationGenerator( - Mockery::mock(CodeCoverageData::class), + $this->createMock(CodeCoverageData::class), Decrement::class, null, [\dirname(__DIR__, 2) . '/Fixtures/Files/InvalidFile'] @@ -172,7 +199,7 @@ public function test_it_throws_correct_error_when_file_is_invalid(): void public function test_it_throws_correct_exception_when_mutator_is_invalid(): void { $generator = $this->createMutationGenerator( - Mockery::mock(CodeCoverageData::class), + $this->createMock(CodeCoverageData::class), ErrorMutator::class ); @@ -190,7 +217,7 @@ private function createMutationGenerator( ?string $whitelistedMutatorName = null, ?MutatorConfig $mutatorConfig = null, array $srcDirs = [] - ) { + ): MutationsGenerator { if ($srcDirs === []) { $srcDirs = [ \dirname(__DIR__, 2) . '/Fixtures/Files/Mutation/OneFile', diff --git a/tests/Mutant/MetricsCalculatorTest.php b/tests/Mutant/MetricsCalculatorTest.php index c79724897..f0b240554 100644 --- a/tests/Mutant/MetricsCalculatorTest.php +++ b/tests/Mutant/MetricsCalculatorTest.php @@ -38,13 +38,13 @@ use Infection\Mutant\MetricsCalculator; use Infection\Process\MutantProcess; use Infection\Process\MutantProcessInterface; -use Mockery; +use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; /** * @internal */ -final class MetricsCalculatorTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class MetricsCalculatorTest extends TestCase { public function test_it_shows_zero_values_by_default(): void { @@ -69,8 +69,8 @@ public function test_it_shows_zero_values_by_default(): void public function test_it_collects_all_values(): void { - $process = Mockery::mock(Process::class); - $process->shouldReceive('stop'); + $process = $this->createMock(Process::class); + $process->method('stop'); $calculator = new MetricsCalculator(); @@ -96,8 +96,10 @@ public function test_it_collects_all_values(): void private function addMutantProcess(MetricsCalculator $calculator, int $resultCode, int $count = 1): void { - $mutantProcess = Mockery::mock(MutantProcessInterface::class); - $mutantProcess->shouldReceive('getResultCode')->times($count)->andReturn($resultCode); + $mutantProcess = $this->createMock(MutantProcessInterface::class); + $mutantProcess->expects($this->exactly($count)) + ->method('getResultCode') + ->willReturn($resultCode); while ($count--) { $calculator->collect($mutantProcess); diff --git a/tests/Mutant/MutantCreatorTest.php b/tests/Mutant/MutantCreatorTest.php index b287a54d5..a8f36e423 100644 --- a/tests/Mutant/MutantCreatorTest.php +++ b/tests/Mutant/MutantCreatorTest.php @@ -39,13 +39,13 @@ use Infection\Mutant\MutantCreator; use Infection\MutationInterface; use Infection\TestFramework\Coverage\CodeCoverageData; -use Mockery\Adapter\Phpunit\MockeryTestCase; use PhpParser\PrettyPrinter\Standard; +use PHPUnit\Framework\TestCase; /** * @internal */ -final class MutantCreatorTest extends MockeryTestCase +final class MutantCreatorTest extends TestCase { private const TEST_FILE_NAME = '/mutant.hash.infection.php'; @@ -56,7 +56,6 @@ final class MutantCreatorTest extends MockeryTestCase protected function setUp(): void { - parent::setUp(); $this->directory = \sys_get_temp_dir() . '/infection/MutantCreator'; mkdir($this->directory, 0777, true); touch($this->directory . self::TEST_FILE_NAME); @@ -77,25 +76,26 @@ protected function tearDown(): void public function test_it_uses_avaialable_file_if_hash_is_the_same(): void { - $standard = \Mockery::mock(Standard::class); - $standard->shouldReceive('prettyPrintFile')->andReturn('The Print'); + $standard = $this->createMock(Standard::class); + $standard->method('prettyPrintFile') + ->willReturn('The Print'); - $differ = \Mockery::mock(Differ::class); - $differ->shouldReceive('diff') - ->withArgs(['The Print', 'andReturn('This is the Diff'); + $differ = $this->createMock(Differ::class); + $differ->method('diff') + ->with('The Print', 'willReturn('This is the Diff'); - $mutation = \Mockery::mock(MutationInterface::class); - $mutation->shouldReceive('getHash')->andReturn('hash'); - $mutation->shouldReceive('getOriginalFilePath')->andReturn('original/path'); - $mutation->shouldReceive('getOriginalFileAst')->andReturn(['ast']); - $mutation->shouldReceive('getAttributes')->andReturn(['startLine' => 1]); - $mutation->shouldReceive('isOnFunctionSignature')->andReturn(true); - $mutation->shouldReceive('isCoveredByTest')->once()->andReturn(true); + $mutation = $this->createMock(MutationInterface::class); + $mutation->method('getHash')->willReturn('hash'); + $mutation->method('getOriginalFilePath')->willReturn('original/path'); + $mutation->method('getOriginalFileAst')->willReturn(['ast']); + $mutation->method('getAttributes')->willReturn(['startLine' => 1]); + $mutation->method('isOnFunctionSignature')->willReturn(true); + $mutation->expects($this->once())->method('isCoveredByTest')->willReturn(true); - $coverage = \Mockery::mock(CodeCoverageData::class); - $coverage->shouldReceive('hasExecutedMethodOnLine')->andReturn(true); - $coverage->shouldReceive('getAllTestsFor')->andReturn(['test', 'list']); + $coverage = $this->createMock(CodeCoverageData::class); + $coverage->method('hasExecutedMethodOnLine')->willReturn(true); + $coverage->method('getAllTestsFor')->willReturn(['test', 'list']); $creator = new MutantCreator($this->directory, $differ, $standard); $mutant = $creator->create($mutation, $coverage); diff --git a/tests/Mutator/Util/MutatorsGeneratorTest.php b/tests/Mutator/Util/MutatorsGeneratorTest.php index 67640dcdf..3f18cc62a 100644 --- a/tests/Mutator/Util/MutatorsGeneratorTest.php +++ b/tests/Mutator/Util/MutatorsGeneratorTest.php @@ -43,15 +43,16 @@ use Infection\Mutator\Util\MutatorsGenerator; use Infection\Tests\Fixtures\StubMutator; use Infection\Visitor\ReflectionVisitor; -use Mockery; use PhpParser\Node; use PhpParser\Node\Expr\BinaryOp\Plus as PlusNode; use PhpParser\Node\Scalar\DNumber; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; /** * @internal */ -final class MutatorsGeneratorTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class MutatorsGeneratorTest extends TestCase { private static $countDefaultMutators = 0; @@ -64,8 +65,7 @@ public static function setUpBeforeClass(): void public function test_no_setting_returns_the_default_mutators(): void { - $mutatorGenerator = new MutatorsGenerator([]); - $mutators = $mutatorGenerator->generate(); + $mutators = (new MutatorsGenerator([]))->generate(); $this->assertCount(self::$countDefaultMutators, $mutators); } @@ -125,9 +125,12 @@ public function test_it_throws_an_error_if_profile_does_not_exist(): void public function test_it_keeps_settings(): void { - /** @var \Mockery\MockInterface|\ReflectionClass $reflectionMock */ - $reflectionMock = Mockery::mock(\ReflectionClass::class); - $reflectionMock->shouldReceive('getName')->once()->andReturn('A'); + /** @var MockObject|\ReflectionClass $reflectionMock */ + $reflectionMock = $this->createMock(\ReflectionClass::class); + $reflectionMock->expects($this->once()) + ->method('getName') + ->willReturn('A'); + $plusNode = $this->getPlusNode('B', $reflectionMock); $mutatorGenerator = new MutatorsGenerator([ @@ -145,9 +148,12 @@ public function test_it_keeps_settings(): void public function test_it_keeps_settings_when_applied_to_profiles(): void { - /** @var \Mockery\MockInterface|\ReflectionClass $reflectionMock */ - $reflectionMock = Mockery::mock(\ReflectionClass::class); - $reflectionMock->shouldReceive('getName')->times(3)->andReturn('A'); + /** @var MockObject|\ReflectionClass $reflectionMock */ + $reflectionMock = $this->createMock(\ReflectionClass::class); + $reflectionMock->expects($this->exactly(3)) + ->method('getName') + ->willReturn('A'); + $plusNode = $this->getPlusNode('B', $reflectionMock); $falseNode = $this->getBoolNode('false', 'B', $reflectionMock); $trueNode = $this->getBoolNode('true', 'B', $reflectionMock); @@ -193,8 +199,12 @@ public function test_it_combines_custom_mutators_with_the_other_mutators(): void public function test_it_can_set_a_single_item_with_a_setting(): void { - $reflectionMock = Mockery::mock(\ReflectionClass::class); - $reflectionMock->shouldReceive('getName')->times(2)->andReturn('A'); + /** @var MockObject|\ReflectionClass $reflectionMock */ + $reflectionMock = $this->createMock(\ReflectionClass::class); + $reflectionMock->expects($this->exactly(2)) + ->method('getName') + ->willReturn('A'); + $falseNode = $this->getBoolNode('false', 'B', $reflectionMock); $trueNode = $this->getBoolNode('true', 'B', $reflectionMock); diff --git a/tests/Process/Builder/ProcessBuilderTest.php b/tests/Process/Builder/ProcessBuilderTest.php index 2742869b7..e85c3befb 100644 --- a/tests/Process/Builder/ProcessBuilderTest.php +++ b/tests/Process/Builder/ProcessBuilderTest.php @@ -38,18 +38,20 @@ use Infection\Mutant\MutantInterface; use Infection\Process\Builder\ProcessBuilder; use Infection\TestFramework\AbstractTestFrameworkAdapter; -use Mockery; +use PHPUnit\Framework\TestCase; /** * @internal */ -final class ProcessBuilderTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class ProcessBuilderTest extends TestCase { public function test_getProcessForInitialTestRun_has_no_timeout(): void { - $fwAdapter = Mockery::mock(AbstractTestFrameworkAdapter::class); - $fwAdapter->shouldReceive('getInitialTestRunCommandLine', ['buildInitialConfigFile'])->andReturn(['/usr/bin/php']); - $fwAdapter->shouldReceive('buildInitialConfigFile')->andReturn('buildInitialConfigFile'); + $fwAdapter = $this->createMock(AbstractTestFrameworkAdapter::class); + $fwAdapter->method('getInitialTestRunCommandLine') + ->willReturn(['/usr/bin/php']); + $fwAdapter->method('buildInitialConfigFile') + ->willReturn('buildInitialConfigFile'); $builder = new ProcessBuilder($fwAdapter, 100); @@ -61,13 +63,15 @@ public function test_getProcessForInitialTestRun_has_no_timeout(): void public function test_getProcessForMutant_has_timeout(): void { - $fwAdapter = Mockery::mock(AbstractTestFrameworkAdapter::class); - $fwAdapter->shouldReceive('getMutantCommandLine', ['buildMutationConfigFile'])->andReturn(['/usr/bin/php']); - $fwAdapter->shouldReceive('buildMutationConfigFile')->andReturn('buildMutationConfigFile'); + $fwAdapter = $this->createMock(AbstractTestFrameworkAdapter::class); + $fwAdapter->method('getMutantCommandLine') + ->willReturn(['/usr/bin/php']); + $fwAdapter->method('buildMutationConfigFile') + ->willReturn('buildMutationConfigFile'); $builder = new ProcessBuilder($fwAdapter, 100); - $process = $builder->getProcessForMutant(Mockery::mock(MutantInterface::class))->getProcess(); + $process = $builder->getProcessForMutant($this->createMock(MutantInterface::class))->getProcess(); $this->assertContains('/usr/bin/php', $process->getCommandLine()); $this->assertSame(100.0, $process->getTimeout()); diff --git a/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php b/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php index 87835d91d..338778467 100644 --- a/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php +++ b/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php @@ -39,24 +39,23 @@ use Infection\Events\InitialTestSuiteStarted; use Infection\Process\Listener\InitialTestsConsoleLoggerSubscriber; use Infection\TestFramework\AbstractTestFrameworkAdapter; -use Mockery; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\OutputInterface; /** * @internal */ -final class InitialTestsConsoleLoggerSubscriberTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class InitialTestsConsoleLoggerSubscriberTest extends TestCase { public function test_it_reacts_on_initial_test_suite_run(): void { - $output = Mockery::mock(OutputInterface::class); - $output->shouldReceive('isDecorated'); - $output->shouldReceive('writeln'); - $output->shouldReceive('getVerbosity')->andReturn(OutputInterface::VERBOSITY_QUIET); + $output = $this->createMock(OutputInterface::class); + $output->method('getVerbosity') + ->willReturn(OutputInterface::VERBOSITY_QUIET); - $testFramework = Mockery::mock(AbstractTestFrameworkAdapter::class); - $testFramework->shouldReceive('getName')->once(); - $testFramework->shouldReceive('getVersion')->once(); + $testFramework = $this->createMock(AbstractTestFrameworkAdapter::class); + $testFramework->expects($this->once()) + ->method('getVersion'); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new InitialTestsConsoleLoggerSubscriber($output, $testFramework)); @@ -66,19 +65,24 @@ public function test_it_reacts_on_initial_test_suite_run(): void public function test_it_sets_test_framework_version_as_unknown_in_case_of_exception(): void { - $output = Mockery::mock(OutputInterface::class); - $output->shouldReceive('isDecorated'); - $output->shouldReceive('writeln')->once()->withArgs([[ + $output = $this->createMock(OutputInterface::class); + $output->expects($this->once()) + ->method('writeln') + ->with([ 'Running initial test suite...', '', 'PHPUnit version: unknown', '', - ]]); - $output->shouldReceive('getVerbosity')->andReturn(OutputInterface::VERBOSITY_QUIET); + ]); + $output->method('getVerbosity') + ->willReturn(OutputInterface::VERBOSITY_QUIET); - $testFramework = Mockery::mock(AbstractTestFrameworkAdapter::class); - $testFramework->shouldReceive('getName')->once()->andReturn('PHPUnit'); - $testFramework->shouldReceive('getVersion')->andThrow(\InvalidArgumentException::class); + $testFramework = $this->createMock(AbstractTestFrameworkAdapter::class); + $testFramework->expects($this->once()) + ->method('getName') + ->willReturn('PHPUnit'); + $testFramework->method('getVersion') + ->will($this->throwException(new \InvalidArgumentException())); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new InitialTestsConsoleLoggerSubscriber($output, $testFramework)); diff --git a/tests/Process/MutantProcessTest.php b/tests/Process/MutantProcessTest.php index 4e08b705c..07caf7acf 100644 --- a/tests/Process/MutantProcessTest.php +++ b/tests/Process/MutantProcessTest.php @@ -41,86 +41,130 @@ use Infection\Mutator\ZeroIteration\For_; use Infection\Process\MutantProcess; use Infection\TestFramework\AbstractTestFrameworkAdapter; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; /** * @internal */ -final class MutantProcessTest extends MockeryTestCase +final class MutantProcessTest extends TestCase { - public function test_it_handles_not_covered_mutant(): void + /** + * @var MutantProcess + */ + private $mutantProcess; + + /** + * @var MockObject|Process + */ + private $process; + + /** + * @var MockObject|MutantInterface + */ + private $mutant; + + /** + * @var MockObject|AbstractTestFrameworkAdapter + */ + private $adapter; + + protected function setUp(): void { - $process = Mockery::mock(Process::class); - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(false); - $testFrameworkAdapter = Mockery::mock(AbstractTestFrameworkAdapter::class); + $this->process = $this->createMock(Process::class); + $this->mutant = $this->createMock(MutantInterface::class); + $this->adapter = $this->createMock(AbstractTestFrameworkAdapter::class); + + $this->mutantProcess = new MutantProcess($this->process, $this->mutant, $this->adapter); + } - $mutantProcess = new MutantProcess($process, $mutant, $testFrameworkAdapter); + public function test_it_handles_not_covered_mutant(): void + { + $this->mutant + ->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(false); - $this->assertSame(MutantProcess::CODE_NOT_COVERED, $mutantProcess->getResultCode()); + $this->assertSame(MutantProcess::CODE_NOT_COVERED, $this->mutantProcess->getResultCode()); } public function test_it_handles_timeout(): void { - $process = Mockery::mock(Process::class); - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(true); - $testFrameworkAdapter = Mockery::mock(AbstractTestFrameworkAdapter::class); + $this->mutant + ->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(true); - $mutantProcess = new MutantProcess($process, $mutant, $testFrameworkAdapter); - $mutantProcess->markTimeout(); + $this->mutantProcess->markTimeout(); - $this->assertSame(MutantProcess::CODE_TIMED_OUT, $mutantProcess->getResultCode()); + $this->assertSame(MutantProcess::CODE_TIMED_OUT, $this->mutantProcess->getResultCode()); } public function test_it_handles_error(): void { - $process = Mockery::mock(Process::class); - $process->shouldReceive('getExitCode')->once()->andReturn(126); - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(true); - $testFrameworkAdapter = Mockery::mock(AbstractTestFrameworkAdapter::class); + $this->mutant + ->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(true); - $mutantProcess = new MutantProcess($process, $mutant, $testFrameworkAdapter); + $this->process + ->expects($this->once()) + ->method('getExitCode') + ->willReturn(126); - $this->assertSame(MutantProcess::CODE_ERROR, $mutantProcess->getResultCode()); + $this->assertSame(MutantProcess::CODE_ERROR, $this->mutantProcess->getResultCode()); } public function test_it_handles_escaped_mutant(): void { - $process = Mockery::mock(Process::class); - $process->shouldReceive('getExitCode')->once()->andReturn(0); - $process->shouldReceive('getOutput')->once()->andReturn('...'); - - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(true); - - $testFrameworkAdapter = Mockery::mock(AbstractTestFrameworkAdapter::class); - $testFrameworkAdapter->shouldReceive('testsPass')->once()->andReturn(true); - - $mutantProcess = new MutantProcess($process, $mutant, $testFrameworkAdapter); - - $this->assertSame(MutantProcess::CODE_ESCAPED, $mutantProcess->getResultCode()); + $this->mutant + ->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(true); + + $this->process + ->expects($this->once()) + ->method('getExitCode') + ->willReturn(0); + + $this->process + ->expects($this->once()) + ->method('getOutput') + ->willReturn('...'); + + $this->adapter + ->expects($this->once()) + ->method('testsPass') + ->willReturn(true); + + $this->assertSame(MutantProcess::CODE_ESCAPED, $this->mutantProcess->getResultCode()); } public function test_it_handles_killed_mutant(): void { - $process = Mockery::mock(Process::class); - $process->shouldReceive('getExitCode')->once()->andReturn(0); - $process->shouldReceive('getOutput')->once()->andReturn('...'); - - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(true); - - $testFrameworkAdapter = Mockery::mock(AbstractTestFrameworkAdapter::class); - $testFrameworkAdapter->shouldReceive('testsPass')->once()->andReturn(false); - - $mutantProcess = new MutantProcess($process, $mutant, $testFrameworkAdapter); - - $this->assertSame(MutantProcess::CODE_KILLED, $mutantProcess->getResultCode()); - $this->assertSame($mutant, $mutantProcess->getMutant()); + $this->mutant + ->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(true); + + $this->process + ->expects($this->once()) + ->method('getExitCode') + ->willReturn(0); + + $this->process + ->expects($this->once()) + ->method('getOutput') + ->willReturn('...'); + + $this->adapter + ->expects($this->once()) + ->method('testsPass') + ->willReturn(false); + + $this->assertSame(MutantProcess::CODE_KILLED, $this->mutantProcess->getResultCode()); + $this->assertSame($this->mutant, $this->mutantProcess->getMutant()); } public function test_it_knows_its_mutator(): void @@ -128,57 +172,61 @@ public function test_it_knows_its_mutator(): void $mutator = new For_(new MutatorConfig([])); $mutation = $this->createMock(MutationInterface::class); - $mutation->expects($this->once())->method('getMutator')->willReturn($mutator); - - $mutant = $this->createMock(MutantInterface::class); - $mutant->expects($this->once())->method('getMutation')->willReturn($mutation); + $mutation->expects($this->once()) + ->method('getMutator') + ->willReturn($mutator); - $adapter = $this->createMock(AbstractTestFrameworkAdapter::class); + $this->mutant + ->expects($this->once()) + ->method('getMutation') + ->willReturn($mutation); - $process = $this->createMock(Process::class); - - $mutantProcess = new MutantProcess($process, $mutant, $adapter); - - $this->assertSame($mutator, $mutantProcess->getMutator()); + $this->assertSame($mutator, $this->mutantProcess->getMutator()); } public function test_it_knows_its_original_path(): void { - $process = $this->createMOck(Process::class); - $process->expects($this->never())->method($this->anything()); + $this->process + ->expects($this->never()) + ->method($this->anything()); - $adapter = $this->createMock(AbstractTestFrameworkAdapter::class); - $adapter->expects($this->never())->method($this->anything()); + $this->adapter + ->expects($this->never()) + ->method($this->anything()); $mutation = $this->createMock(MutationInterface::class); - $mutation->expects($this->once())->method('getOriginalFilePath')->willReturn('foo/bar'); - $mutant = $this->createMock(MutantInterface::class); - $mutant->expects($this->once())->method('getMutation')->willReturn($mutation); + $mutation->expects($this->once()) + ->method('getOriginalFilePath') + ->willReturn('foo/bar'); - $mutantProcess = new MutantProcess($process, $mutant, $adapter); + $this->mutant + ->expects($this->once()) + ->method('getMutation') + ->willReturn($mutation); - $path = $mutantProcess->getOriginalFilePath(); - - $this->assertSame('foo/bar', $path); + $this->assertSame('foo/bar', $this->mutantProcess->getOriginalFilePath()); } public function test_it_knows_its_original_starting_line(): void { - $process = $this->createMOck(Process::class); - $process->expects($this->never())->method($this->anything()); + $this->process + ->expects($this->never()) + ->method($this->anything()); - $adapter = $this->createMock(AbstractTestFrameworkAdapter::class); - $adapter->expects($this->never())->method($this->anything()); + $this->adapter + ->expects($this->never()) + ->method($this->anything()); $mutation = $this->createMock(MutationInterface::class); - $mutation->expects($this->once())->method('getAttributes')->willReturn(['startLine' => '3']); - $mutant = $this->createMock(MutantInterface::class); - $mutant->expects($this->once())->method('getMutation')->willReturn($mutation); - - $mutantProcess = new MutantProcess($process, $mutant, $adapter); + $mutation->expects($this->once()) + ->method('getAttributes') + ->willReturn(['startLine' => '3']); - $line = $mutantProcess->getOriginalStartingLine(); + $this->mutant + ->expects($this->once()) + ->method('getMutation') + ->willReturn($mutation); - $this->assertSame(3, $line); + $this->assertSame(3, $this->mutantProcess->getOriginalStartingLine()); } } diff --git a/tests/Process/Runner/InitialTestsRunnerTest.php b/tests/Process/Runner/InitialTestsRunnerTest.php index 215c48f4c..df13bd166 100644 --- a/tests/Process/Runner/InitialTestsRunnerTest.php +++ b/tests/Process/Runner/InitialTestsRunnerTest.php @@ -41,30 +41,42 @@ use Infection\Events\InitialTestSuiteStarted; use Infection\Process\Builder\ProcessBuilder; use Infection\Process\Runner\InitialTestsRunner; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; /** * @internal */ -final class InitialTestsRunnerTest extends MockeryTestCase +final class InitialTestsRunnerTest extends TestCase { public function test_it_dispatches_events(): void { - $process = Mockery::mock(Process::class); - $process->shouldReceive('run'); + /** @var MockObject|Process $process */ + $process = $this->createMock(Process::class); - $processBuilder = Mockery::mock(ProcessBuilder::class); - $processBuilder - ->shouldReceive('getProcessForInitialTestRun') - ->withArgs(['', false, []]) - ->andReturn($process); + $process->expects($this->once()) + ->method('run') + ->with($this->callback(function ($processCallback): bool { + $processCallback(Process::OUT); - $eventDispatcher = Mockery::mock(EventDispatcherInterface::class); - $eventDispatcher->shouldReceive('dispatch')->with(Mockery::type(InitialTestSuiteStarted::class)); - $eventDispatcher->shouldReceive('dispatch')->with(Mockery::type(InitialTestCaseCompleted::class)); - $eventDispatcher->shouldReceive('dispatch')->with(Mockery::type(InitialTestSuiteFinished::class)); + return true; + })); + + $processBuilder = $this->createMock(ProcessBuilder::class); + $processBuilder->method('getProcessForInitialTestRun') + ->with('', false, []) + ->willReturn($process); + + /** @var MockObject|EventDispatcherInterface $eventDispatcher */ + $eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $eventDispatcher->expects($this->exactly(3)) + ->method('dispatch') + ->withConsecutive( + $this->isInstanceOf(InitialTestSuiteStarted::class), + $this->isInstanceOf(InitialTestCaseCompleted::class), + $this->isInstanceOf(InitialTestSuiteFinished::class) + ); $testRunner = new InitialTestsRunner($processBuilder, $eventDispatcher); diff --git a/tests/Process/Runner/Parallel/ParallelProcessRunnerTest.php b/tests/Process/Runner/Parallel/ParallelProcessRunnerTest.php index 4b4098bd4..71411604c 100644 --- a/tests/Process/Runner/Parallel/ParallelProcessRunnerTest.php +++ b/tests/Process/Runner/Parallel/ParallelProcessRunnerTest.php @@ -40,15 +40,15 @@ use Infection\Mutant\MutantInterface; use Infection\Process\MutantProcessInterface; use Infection\Process\Runner\Parallel\ParallelProcessRunner; -use Mockery; -use Mockery\Adapter\Phpunit\MockeryTestCase; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Exception\ProcessTimedOutException; use Symfony\Component\Process\Process; /** * @internal */ -final class ParallelProcessRunnerTest extends MockeryTestCase +final class ParallelProcessRunnerTest extends TestCase { public function test_it_does_nothing_when_nothing_to_do(): void { @@ -123,58 +123,86 @@ public function test_it_still_runs_with_negative_thread_count(): void private function buildEventDispatcherWithEventCount($eventCount): EventDispatcherInterface { - /** @var EventDispatcherInterface|Mockery\MockInterface $eventDispatcher */ - $eventDispatcher = Mockery::mock(EventDispatcherInterface::class); - $eventDispatcher->shouldReceive('dispatch')->times($eventCount)->with(Mockery::type(MutantProcessFinished::class)); + /** @var MockObject|EventDispatcherInterface $eventDispatcher */ + $eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $eventDispatcher->expects($this->exactly($eventCount)) + ->method('dispatch') + ->with(new MutantProcessFinished($this->createMock(MutantProcessInterface::class))); return $eventDispatcher; } private function buildUncoveredMutantProcess(): MutantProcessInterface { - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(false); + $mutant = $this->createMock(MutantInterface::class); + $mutant->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(false); - /** @var MutantProcessFinished|Mockery\MockInterface $mutantProcess */ - $mutantProcess = Mockery::mock(MutantProcessInterface::class); - $mutantProcess->shouldReceive('getMutant')->once()->andReturn($mutant); + /** @var MockObject|MutantProcessInterface $mutantProcess */ + $mutantProcess = $this->createMock(MutantProcessInterface::class); + $mutantProcess->expects($this->once()) + ->method('getMutant') + ->willReturn($mutant); return $mutantProcess; } private function buildCoveredMutantProcess(): MutantProcessInterface { - $process = Mockery::mock(Process::class); - $process->shouldReceive('start')->once(); - $process->shouldReceive('checkTimeout')->once(); - $process->shouldReceive('isRunning')->once()->andReturn(false); - - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(true); - - /** @var MutantProcessFinished|Mockery\MockInterface $mutantProcess */ - $mutantProcess = Mockery::mock(MutantProcessInterface::class); - $mutantProcess->shouldReceive('getProcess')->twice()->andReturn($process); - $mutantProcess->shouldReceive('getMutant')->once()->andReturn($mutant); + $process = $this->createMock(Process::class); + $process->expects($this->once()) + ->method('start'); + $process->expects($this->once()) + ->method('checkTimeout'); + $process->expects($this->once()) + ->method('isRunning') + ->willReturn(false); + + $mutant = $this->createMock(MutantInterface::class); + $mutant->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(true); + + /** @var MockObject|MutantProcessInterface $mutantProcess */ + $mutantProcess = $this->createMock(MutantProcessInterface::class); + $mutantProcess->expects($this->exactly(2)) + ->method('getProcess') + ->willReturn($process); + $mutantProcess->expects($this->once()) + ->method('getMutant') + ->willReturn($mutant); return $mutantProcess; } private function buildCoveredMutantProcessWithTimeout(): MutantProcessInterface { - $process = Mockery::mock(Process::class); - $process->shouldReceive('start')->once(); - $process->shouldReceive('checkTimeout')->once()->andThrow(Mockery::mock(ProcessTimedOutException::class)); - $process->shouldReceive('isRunning')->once()->andReturn(false); - - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('isCoveredByTest')->once()->andReturn(true); - - /** @var MutantProcessFinished|Mockery\MockInterface $mutantProcess */ - $mutantProcess = Mockery::mock(MutantProcessInterface::class); - $mutantProcess->shouldReceive('getProcess')->twice()->andReturn($process); - $mutantProcess->shouldReceive('getMutant')->once()->andReturn($mutant); - $mutantProcess->shouldReceive('markTimeout')->once(); + $process = $this->createMock(Process::class); + $process->expects($this->once()) + ->method('start'); + $process->expects($this->once()) + ->method('checkTimeout') + ->will($this->throwException(new ProcessTimedOutException($process, 1))); + $process->expects($this->once()) + ->method('isRunning') + ->willReturn(false); + + $mutant = $this->createMock(MutantInterface::class); + $mutant->expects($this->once()) + ->method('isCoveredByTest') + ->willReturn(true); + + /** @var MockObject|MutantProcessInterface $mutantProcess */ + $mutantProcess = $this->createMock(MutantProcessInterface::class); + $mutantProcess->expects($this->exactly(2)) + ->method('getProcess') + ->willReturn($process); + $mutantProcess->expects($this->once()) + ->method('getMutant') + ->willReturn($mutant); + $mutantProcess->expects($this->once()) + ->method('markTimeout'); return $mutantProcess; } diff --git a/tests/TestFramework/Coverage/CachedTestFileDataProviderTest.php b/tests/TestFramework/Coverage/CachedTestFileDataProviderTest.php index 31d152769..063bc090a 100644 --- a/tests/TestFramework/Coverage/CachedTestFileDataProviderTest.php +++ b/tests/TestFramework/Coverage/CachedTestFileDataProviderTest.php @@ -37,21 +37,21 @@ use Infection\TestFramework\Coverage\CachedTestFileDataProvider; use Infection\TestFramework\Coverage\TestFileDataProvider; -use Mockery; +use PHPUnit\Framework\TestCase; /** * @internal */ -final class CachedTestFileDataProviderTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class CachedTestFileDataProviderTest extends TestCase { public function test_the_second_call_returns_cached_result(): void { $class = 'Test\Class'; - $providerMock = Mockery::mock(TestFileDataProvider::class); - $providerMock->shouldReceive('getTestFileInfo') + $providerMock = $this->createMock(TestFileDataProvider::class); + $providerMock->expects($this->once()) + ->method('getTestFileInfo') ->with($class) - ->once() - ->andReturn(['data']); + ->willReturn(['data']); $infoProvider = new CachedTestFileDataProvider($providerMock); diff --git a/tests/TestFramework/Coverage/CodeCoverageDataTest.php b/tests/TestFramework/Coverage/CodeCoverageDataTest.php index f72767d8c..5915d360f 100644 --- a/tests/TestFramework/Coverage/CodeCoverageDataTest.php +++ b/tests/TestFramework/Coverage/CodeCoverageDataTest.php @@ -41,13 +41,13 @@ use Infection\TestFramework\Coverage\CoverageDoesNotExistException; use Infection\TestFramework\PhpUnit\Coverage\CoverageXmlParser; use Infection\TestFramework\TestFrameworkTypes; -use Mockery; use PhpParser\Node\Scalar\LNumber; +use PHPUnit\Framework\TestCase; /** * @internal */ -final class CodeCoverageDataTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class CodeCoverageDataTest extends TestCase { private $coverageDir = __DIR__ . '/../../Fixtures/Files/phpunit/coverage-xml'; @@ -143,7 +143,7 @@ public function test_it_returns_zero_tests_for_not_covered_function_body_mutator $mutation = new Mutation( $filePath, [], - Mockery::mock(Mutator::class), + $this->createMock(Mutator::class), ['startLine' => 1, 'endLine' => 1], 'PHPParser\Node\Expr\BinaryOp\Plus', false, @@ -163,7 +163,7 @@ public function test_it_returns_tests_for_covered_function_body_mutator(): void $mutation = new Mutation( $filePath, [], - Mockery::mock(Mutator::class), + $this->createMock(Mutator::class), ['startLine' => 26, 'endLine' => 26], 'PHPParser\Node\Expr\BinaryOp\Plus', false, @@ -183,7 +183,7 @@ public function test_it_returns_zero_tests_for_not_covered_function_signature_mu $mutation = new Mutation( $filePath, [], - Mockery::mock(Mutator::class), + $this->createMock(Mutator::class), ['startLine' => 1, 'endLine' => 1], 'PHPParser\Node\Stmt\ClassMethod', true, @@ -203,7 +203,7 @@ public function test_it_returns_tests_for_covered_function_signature_mutator(): $mutation = new Mutation( $filePath, [], - Mockery::mock(Mutator::class), + $this->createMock(Mutator::class), ['startLine' => 24, 'endLine' => 24], 'PHPParser\Node\Stmt\ClassMethod', true, @@ -217,7 +217,7 @@ public function test_it_returns_tests_for_covered_function_signature_mutator(): public function test_it_throws_an_exception_when_no_coverage_found(): void { - $coverageXmlParserMock = Mockery::mock(CoverageXmlParser::class); + $coverageXmlParserMock = $this->createMock(CoverageXmlParser::class); $coverage = new CodeCoverageData('/abc/foo/bar', $coverageXmlParserMock, TestFrameworkTypes::PHPUNIT); @@ -278,8 +278,10 @@ private function getParsedCodeCoverageData(): array private function getCodeCoverageData(): CodeCoverageData { - $coverageXmlParserMock = Mockery::mock(CoverageXmlParser::class); - $coverageXmlParserMock->shouldReceive('parse')->once()->andReturn($this->getParsedCodeCoverageData()); + $coverageXmlParserMock = $this->createMock(CoverageXmlParser::class); + $coverageXmlParserMock->expects($this->once()) + ->method('parse') + ->willReturn($this->getParsedCodeCoverageData()); return new CodeCoverageData($this->coverageDir, $coverageXmlParserMock, TestFrameworkTypes::PHPUNIT); } diff --git a/tests/TestFramework/FactoryTest.php b/tests/TestFramework/FactoryTest.php index 9199c2e55..fe9514078 100644 --- a/tests/TestFramework/FactoryTest.php +++ b/tests/TestFramework/FactoryTest.php @@ -41,24 +41,24 @@ use Infection\TestFramework\PhpUnit\Config\Path\PathReplacer; use Infection\TestFramework\PhpUnit\Config\XmlConfigurationHelper; use Infection\Utils\VersionParser; -use Mockery; +use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; /** * @internal */ -final class FactoryTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class FactoryTest extends TestCase { public function test_it_throws_an_exception_if_it_cant_find_the_testframework(): void { $factory = new Factory( '', '', - Mockery::mock(TestFrameworkConfigLocatorInterface::class), + $this->createMock(TestFrameworkConfigLocatorInterface::class), new XmlConfigurationHelper(new PathReplacer(new Filesystem()), ''), '', new InfectionConfig(new \stdClass(), new Filesystem(), ''), - Mockery::mock(VersionParser::class) + $this->createMock(VersionParser::class) ); $this->expectException(\InvalidArgumentException::class); diff --git a/tests/TestFramework/PhpSpec/Adapter/PhpSpecAdapterTest.php b/tests/TestFramework/PhpSpec/Adapter/PhpSpecAdapterTest.php index 7f686da3e..c59877dbc 100644 --- a/tests/TestFramework/PhpSpec/Adapter/PhpSpecAdapterTest.php +++ b/tests/TestFramework/PhpSpec/Adapter/PhpSpecAdapterTest.php @@ -41,12 +41,12 @@ use Infection\TestFramework\PhpSpec\Config\Builder\InitialConfigBuilder; use Infection\TestFramework\PhpSpec\Config\Builder\MutationConfigBuilder; use Infection\Utils\VersionParser; -use Mockery; +use PHPUnit\Framework\TestCase; /** * @internal */ -final class PhpSpecAdapterTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class PhpSpecAdapterTest extends TestCase { public function test_it_has_a_name(): void { @@ -127,12 +127,12 @@ public function test_it_catches_fatal_errors_from_start(): void private function getAdapter(): PhpSpecAdapter { - $executableFined = Mockery::mock(AbstractExecutableFinder::class); - $initialConfigBuilder = Mockery::mock(InitialConfigBuilder::class); - $mutationConfigBuilder = Mockery::mock(MutationConfigBuilder::class); - $cliArgumentsBuilder = Mockery::mock(CommandLineArgumentsAndOptionsBuilder::class); - $versionParser = Mockery::mock(VersionParser::class); - - return new PhpSpecAdapter($executableFined, $initialConfigBuilder, $mutationConfigBuilder, $cliArgumentsBuilder, $versionParser); + return new PhpSpecAdapter( + $this->createMock(AbstractExecutableFinder::class), + $this->createMock(InitialConfigBuilder::class), + $this->createMock(MutationConfigBuilder::class), + $this->createMock(CommandLineArgumentsAndOptionsBuilder::class), + $this->createMock(VersionParser::class) + ); } } diff --git a/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php b/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php index f2847bef0..4ffc5d1b1 100644 --- a/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php +++ b/tests/TestFramework/PhpSpec/Config/Builder/MutationConfigBuilderTest.php @@ -39,13 +39,13 @@ use Infection\MutationInterface; use Infection\TestFramework\PhpSpec\Config\Builder\MutationConfigBuilder; use Infection\Utils\TmpDirectoryCreator; -use Mockery; +use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; /** * @internal */ -final class MutationConfigBuilderTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class MutationConfigBuilderTest extends TestCase { private $tmpDir; @@ -77,13 +77,17 @@ public function test_it_builds_path_to_mutation_config_file(): void $projectDir = '/project/dir'; $originalYamlConfigPath = __DIR__ . '/../../../../Fixtures/Files/phpspec/phpspec.yml'; - $mutation = Mockery::mock(MutationInterface::class); - $mutation->shouldReceive('getHash')->andReturn('a1b2c3'); - $mutation->shouldReceive('getOriginalFilePath')->andReturn('/original/file/path'); + $mutation = $this->createMock(MutationInterface::class); + $mutation->method('getHash') + ->willReturn('a1b2c3'); + $mutation->method('getOriginalFilePath') + ->willReturn('/original/file/path'); - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('getMutation')->andReturn($mutation); - $mutant->shouldReceive('getMutatedFilePath')->andReturn('/mutated/file/path'); + $mutant = $this->createMock(MutantInterface::class); + $mutant->method('getMutation') + ->willReturn($mutation); + $mutant->method('getMutatedFilePath') + ->willReturn('/mutated/file/path'); // TODO for PhpSpec pass file content as well // TODO test phpspec after that @@ -97,13 +101,17 @@ public function test_it_adds_original_bootstrap_file_to_custom_autoload(): void $projectDir = '/project/dir'; $originalYamlConfigPath = __DIR__ . '/../../../../Fixtures/Files/phpspec/phpspec.with.bootstrap.yml'; - $mutation = Mockery::mock(MutationInterface::class); - $mutation->shouldReceive('getHash')->andReturn('a1b2c3'); - $mutation->shouldReceive('getOriginalFilePath')->andReturn('/original/file/path'); - - $mutant = Mockery::mock(MutantInterface::class); - $mutant->shouldReceive('getMutation')->andReturn($mutation); - $mutant->shouldReceive('getMutatedFilePath')->andReturn('/mutated/file/path'); + $mutation = $this->createMock(MutationInterface::class); + $mutation->method('getHash') + ->willReturn('a1b2c3'); + $mutation->method('getOriginalFilePath') + ->willReturn('/original/file/path'); + + $mutant = $this->createMock(MutantInterface::class); + $mutant->method('getMutation') + ->willReturn($mutation); + $mutant->method('getMutatedFilePath') + ->willReturn('/mutated/file/path'); $builder = new MutationConfigBuilder($this->tmpDir, $originalYamlConfigPath, $projectDir); diff --git a/tests/TestFramework/PhpUnit/Config/Builder/InitialConfigBuilderTest.php b/tests/TestFramework/PhpUnit/Config/Builder/InitialConfigBuilderTest.php index c3059ebc5..65f8dca85 100644 --- a/tests/TestFramework/PhpUnit/Config/Builder/InitialConfigBuilderTest.php +++ b/tests/TestFramework/PhpUnit/Config/Builder/InitialConfigBuilderTest.php @@ -39,14 +39,14 @@ use Infection\TestFramework\PhpUnit\Config\Path\PathReplacer; use Infection\TestFramework\PhpUnit\Config\XmlConfigurationHelper; use Infection\Utils\TmpDirectoryCreator; -use Mockery; +use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use function Infection\Tests\normalizePath as p; /** * @internal */ -final class InitialConfigBuilderTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class InitialConfigBuilderTest extends TestCase { public const HASH = 'a1b2c3'; @@ -239,7 +239,7 @@ public function executionOrderProvider(): \Generator yield 'PHPUnit 7.3.1 runs dependency resolver' => ['7.3.1', 'resolveDependencies', 1]; } - protected function queryXpath(string $xml, string $query) + private function queryXpath(string $xml, string $query) { $dom = new \DOMDocument(); $dom->loadXML($xml); diff --git a/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php b/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php index 157190f67..6991d6621 100644 --- a/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php +++ b/tests/TestFramework/PhpUnit/Config/Builder/MutationConfigBuilderTest.php @@ -41,14 +41,14 @@ use Infection\TestFramework\PhpUnit\Config\Path\PathReplacer; use Infection\TestFramework\PhpUnit\Config\XmlConfigurationHelper; use Infection\Utils\TmpDirectoryCreator; -use Mockery; +use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use function Infection\Tests\normalizePath as p; /** * @internal */ -final class MutationConfigBuilderTest extends Mockery\Adapter\Phpunit\MockeryTestCase +final class MutationConfigBuilderTest extends TestCase { public const HASH = 'a1b2c3'; @@ -89,14 +89,21 @@ protected function setUp(): void $projectDir = '/project/dir'; $phpunitXmlPath = __DIR__ . '/../../../../Fixtures/Files/phpunit/phpunit.xml'; - $this->mutation = Mockery::mock(MutationInterface::class); - $this->mutation->shouldReceive('getHash')->andReturn(self::HASH); - $this->mutation->shouldReceive('getOriginalFilePath')->andReturn('/original/file/path'); - - $this->mutant = Mockery::mock(MutantInterface::class); - $this->mutant->shouldReceive('getMutation')->andReturn($this->mutation); - $this->mutant->shouldReceive('getMutatedFilePath')->andReturn('/mutated/file/path'); - $this->mutant->shouldReceive('getMutatedFileCode')->andReturn('mutation = $this->createMock(MutationInterface::class); + $this->mutation + ->method('getHash') + ->willReturn(self::HASH); + $this->mutation + ->method('getOriginalFilePath') + ->willReturn('/original/file/path'); + + $this->mutant = $this->createMock(MutantInterface::class); + $this->mutant + ->method('getMutation') + ->willReturn($this->mutation); + $this->mutant + ->method('getMutatedFilePath') + ->willReturn('/mutated/file/path'); $this->xmlConfigurationHelper = new XmlConfigurationHelper(new PathReplacer($this->fileSystem, $this->pathToProject), ''); @@ -115,7 +122,9 @@ protected function tearDown(): void public function test_it_builds_path_to_mutation_config_file(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $this->assertSame( $this->tmpDir . '/phpunitConfiguration.a1b2c3.infection.xml', @@ -125,7 +134,9 @@ public function test_it_builds_path_to_mutation_config_file(): void public function test_it_sets_custom_autoloader(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $configurationPath = $this->builder->build($this->mutant); @@ -145,7 +156,10 @@ public function test_it_sets_custom_autoloader(): void public function test_it_sets_custom_autoloader_when_attribute_is_absent(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); + $phpunitXmlPath = __DIR__ . '/../../../../Fixtures/Files/phpunit/phpuit_without_bootstrap.xml'; $this->builder = new MutationConfigBuilder( $this->tmpDir, @@ -172,7 +186,9 @@ public function test_it_sets_custom_autoloader_when_attribute_is_absent(): void public function test_it_sets_stop_on_failure_flag(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $configurationPath = $this->builder->build($this->mutant); @@ -185,7 +201,9 @@ public function test_it_sets_stop_on_failure_flag(): void public function test_it_sets_colors_flag(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $configurationPath = $this->builder->build($this->mutant); @@ -198,7 +216,9 @@ public function test_it_sets_colors_flag(): void public function test_it_handles_root_test_suite(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $phpunitXmlPath = __DIR__ . '/../../../../Fixtures/Files/phpunit/phpunit_root_test_suite.xml'; $replacer = new PathReplacer($this->fileSystem, $this->pathToProject); @@ -218,7 +238,9 @@ public function test_it_handles_root_test_suite(): void public function test_it_removes_original_loggers(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $configurationPath = $this->builder->build($this->mutant); @@ -230,7 +252,9 @@ public function test_it_removes_original_loggers(): void public function test_it_removes_printer_class(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $configurationPath = $this->builder->build($this->mutant); @@ -246,7 +270,9 @@ public function test_it_removes_printer_class(): void */ public function test_it_sets_sorted_list_of_test_files(array $coverageTests, array $expectedFiles): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn($coverageTests); + $this->mutant + ->method('getCoverageTests') + ->willReturn($coverageTests); $configurationPath = $this->builder->build($this->mutant); @@ -264,7 +290,9 @@ public function test_it_sets_sorted_list_of_test_files(array $coverageTests, arr public function test_it_removes_default_test_suite(): void { - $this->mutant->shouldReceive('getCoverageTests')->andReturn([]); + $this->mutant + ->method('getCoverageTests') + ->willReturn([]); $configurationPath = $this->builder->build($this->mutant); @@ -333,7 +361,7 @@ public function coverageTestsProvider(): array ]; } - protected function queryXpath(string $xml, string $query) + private function queryXpath(string $xml, string $query) { $dom = new \DOMDocument(); $dom->loadXML($xml);