feat(pending-higher-order-tests): adds code and tests

This commit is contained in:
Nuno Maduro
2020-06-04 01:33:33 +02:00
parent b0680b7e2c
commit c81dce0f6d
6 changed files with 43 additions and 5 deletions

View File

@ -78,6 +78,9 @@
] ]
}, },
"extra": { "extra": {
"branch-alias": {
"dev-master": "0.2.x-dev"
},
"laravel": { "laravel": {
"providers": [ "providers": [
"Pest\\Laravel\\PestServiceProvider" "Pest\\Laravel\\PestServiceProvider"

View File

@ -20,3 +20,4 @@ parameters:
- "# with null as default value#" - "# with null as default value#"
- "#Using \\$this in static method#" - "#Using \\$this in static method#"
- "#has parameter \\$closure with default value.#" - "#has parameter \\$closure with default value.#"
- "#has parameter \\$description with default value.#"

View File

@ -88,6 +88,8 @@ final class Command extends BaseCommand
*/ */
$this->arguments = AddsDefaults::to($this->arguments); $this->arguments = AddsDefaults::to($this->arguments);
LoadStructure::in($this->testSuite->rootPath);
$testRunner = new TestRunner($this->arguments['loader']); $testRunner = new TestRunner($this->arguments['loader']);
$testSuite = $this->arguments['test']; $testSuite = $this->arguments['test'];
@ -109,7 +111,6 @@ final class Command extends BaseCommand
$this->arguments['test'] = $testSuite; $this->arguments['test'] = $testSuite;
} }
LoadStructure::in($this->testSuite->rootPath);
AddsTests::to($testSuite, $this->testSuite); AddsTests::to($testSuite, $this->testSuite);
return $testRunner; return $testRunner;

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Pest\Repositories; namespace Pest\Repositories;
use Pest\Exceptions\ShouldNotHappen;
use Pest\Exceptions\TestAlreadyExist; use Pest\Exceptions\TestAlreadyExist;
use Pest\Exceptions\TestCaseAlreadyInUse; use Pest\Exceptions\TestCaseAlreadyInUse;
use Pest\Exceptions\TestCaseClassOrTraitNotFound; use Pest\Exceptions\TestCaseClassOrTraitNotFound;
@ -54,7 +55,6 @@ final class TestRepository
if ($testCase->class !== \PHPUnit\Framework\TestCase::class) { if ($testCase->class !== \PHPUnit\Framework\TestCase::class) {
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename); throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
} }
$testCase->class = $class; $testCase->class = $class;
} elseif (trait_exists($class)) { } elseif (trait_exists($class)) {
$testCase->traits[] = $class; $testCase->traits[] = $class;
@ -62,9 +62,9 @@ final class TestRepository
} }
$testCase $testCase
->factoryProxies ->factoryProxies
// Consider set the real line here. // Consider set the real line here.
->add($filename, 0, 'addGroups', [$groups]); ->add($filename, 0, 'addGroups', [$groups]);
} }
}; };
@ -113,6 +113,10 @@ final class TestRepository
*/ */
public function set(TestCaseFactory $test): void public function set(TestCaseFactory $test): void
{ {
if ($test->description === null) {
throw ShouldNotHappen::fromMessage('Trying to create a test without description.');
}
if (array_key_exists(sprintf('%s@%s', $test->filename, $test->description), $this->state)) { if (array_key_exists(sprintf('%s@%s', $test->filename, $test->description), $this->state)) {
throw new TestAlreadyExist($test->filename, $test->description); throw new TestAlreadyExist($test->filename, $test->description);
} }

View File

@ -0,0 +1,29 @@
<?php
use PHPUnit\Framework\TestCase;
uses(Gettable::class);
/**
* @return TestCase|Gettable
*/
function get(string $route)
{
return test()->get($route);
}
trait Gettable
{
/**
* @return TestCase|Gettable
*/
public function get(string $route)
{
assertNotEmpty($route);
return $this;
}
}
get('foo')->get('bar')->assertTrue(true);
get('foo')->assertTrue(true);