Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed May 3, 2021
1 parent c725600 commit f215a8c
Show file tree
Hide file tree
Showing 5 changed files with 407 additions and 4 deletions.
5 changes: 5 additions & 0 deletions devTools/phpstan-src-baseline.neon
Expand Up @@ -305,6 +305,11 @@ parameters:
count: 1
path: ../src/TestFramework/Coverage/XmlReport/XPathFactory.php

-
message: "#^Method Infection\\\\TestFramework\\\\PhpUnit\\\\Adapter\\\\PestAdapterFactory\\:\\:create\\(\\) has parameter \\$sourceDirectories with no value type specified in iterable type array\\.$#"
count: 1
path: ../src/TestFramework/PhpUnit/Adapter/PestAdapterFactory.php

-
message: "#^Only booleans are allowed in an if condition, int given\\.$#"
count: 3
Expand Down
34 changes: 31 additions & 3 deletions src/TestFramework/PhpUnit/Adapter/PestAdapter.php
Expand Up @@ -35,13 +35,20 @@

namespace Infection\TestFramework\PhpUnit\Adapter;

use Infection\AbstractTestFramework\MemoryUsageAware;
use Infection\AbstractTestFramework\TestFrameworkAdapter;
use Infection\PhpParser\Visitor\IgnoreNode\PhpUnitCodeCoverageAnnotationIgnorer;
use Infection\TestFramework\IgnoresAdditionalNodes;
use Infection\TestFramework\ProvidesInitialRunOnlyOptions;
use function Safe\preg_match;
use function sprintf;
use function Safe\sprintf;

class PestAdapter implements TestFrameworkAdapter
/**
* @internal
*/
final class PestAdapter implements IgnoresAdditionalNodes, MemoryUsageAware, ProvidesInitialRunOnlyOptions, TestFrameworkAdapter
{
private const NAME = 'pest';
private const NAME = 'Pest';

private PhpUnitAdapter $phpUnitAdapter;

Expand Down Expand Up @@ -101,4 +108,25 @@ public function getInitialTestsFailRecommendations(string $commandLine): string
{
return $this->phpUnitAdapter->getInitialTestsFailRecommendations($commandLine);
}

public function getMemoryUsed(string $output): float
{
return $this->phpUnitAdapter->getMemoryUsed($output);
}

/**
* @return PhpUnitCodeCoverageAnnotationIgnorer[]
*/
public function getNodeIgnorers(): array
{
return [new PhpUnitCodeCoverageAnnotationIgnorer()];
}

/**
* @return string[]
*/
public function getInitialRunOnlyOptions(): array
{
return $this->phpUnitAdapter->getInitialRunOnlyOptions();
}
}
Expand Up @@ -115,7 +115,6 @@ public function build(
$this->setCustomBootstrapPath($customAutoloadFilePath, $xPath);
$this->setFilteredTestsToRun($tests, $dom, $xPath);

// todo where is caching? we had it before I guess
file_put_contents(
$customAutoloadFilePath,
$this->createCustomAutoloadWithInterceptor(
Expand Down
@@ -0,0 +1,71 @@
<?php
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

namespace Infection\Tests\TestFramework\PhpUnit\Adapter;

use Infection\TestFramework\PhpUnit\Adapter\PestAdapterFactory;
use PHPUnit\Framework\TestCase;

/**
* @group integration
*/
final class PestAdapterFactoryTest extends TestCase
{
public function test_it_can_create_an_adapter(): void
{
$adapter = PestAdapterFactory::create(
'/path/to/pest',
'/tmp',
__DIR__ . '/../../../Fixtures/Files/phpunit/phpunit.xml',
'/path/to/config-dir',
'/path/to/junit.xml',
'/path/to/project',
[],
true
);

$this->assertSame('Pest', $adapter->getName());
}

public function test_it_has_a_name(): void
{
$this->assertSame('pest', PestAdapterFactory::getAdapterName());
}

public function test_it_has_an_executable(): void
{
$this->assertSame('pest', PestAdapterFactory::getExecutableName());
}
}

0 comments on commit f215a8c

Please sign in to comment.