Skip to content

Commit

Permalink
Remove Mockery as dev dependency (#574)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sidz authored and maks-rafalko committed Nov 20, 2018
1 parent 739e782 commit ab723af
Show file tree
Hide file tree
Showing 29 changed files with 761 additions and 689 deletions.
1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -77,7 +77,6 @@
"webmozart/assert": "^1.3"
},
"require-dev": {
"mockery/mockery": "^1.1",
"phpunit/phpunit": "^6"
},
"bin": ["bin/infection"]
Expand Down
115 changes: 1 addition & 114 deletions composer.lock

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

2 changes: 0 additions & 2 deletions devTools/phpstan-tests.neon
@@ -1,5 +1,3 @@
parameters:
excludes_analyse:
- %currentWorkingDirectory%/tests/Fixtures/*
ignoreErrors:
- '#Call to an undefined method Mockery#'
5 changes: 0 additions & 5 deletions phpunit.xml.dist
Expand Up @@ -18,14 +18,9 @@
</whitelist>
</filter>

<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
</listeners>

<groups>
<exclude>
<group>large</group>
</exclude>
</groups>

</phpunit>
18 changes: 8 additions & 10 deletions tests/Config/ValueProvider/AbstractBaseProviderTest.php
Expand Up @@ -35,24 +35,24 @@

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;

/**
* @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);
Expand All @@ -61,28 +61,26 @@ protected function getInputStream($input)
return $stream;
}

protected function createOutputInterface()
protected function createOutputInterface(): StreamOutput
{
return new StreamOutput(fopen('php://memory', 'r+b', false));
}

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;
Expand Down
39 changes: 14 additions & 25 deletions tests/Config/ValueProvider/ExcludeDirsProviderTest.php
Expand Up @@ -37,7 +37,6 @@

use Infection\Config\ConsoleHelper;
use Infection\Config\ValueProvider\ExcludeDirsProvider;
use Mockery;
use Symfony\Component\Filesystem\Filesystem;

/**
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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'],
Expand All @@ -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'],
Expand Down

0 comments on commit ab723af

Please sign in to comment.