Skip to content

Commit

Permalink
Task #84 Add PHPSpecGenerator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msvrtan committed Jul 29, 2017
1 parent a556af5 commit 1275f0c
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 6 deletions.
47 changes: 41 additions & 6 deletions tests/NullDev/PhpSpecSkeleton/SpecGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,59 @@
namespace tests\NullDev\PhpSpecSkeleton;

use NullDev\PhpSpecSkeleton\SpecGenerator;
use PHPUnit_Framework_TestCase;
use NullDev\Skeleton\CodeGenerator\PhpParserGenerator;
use NullDev\Skeleton\Source\ImprovedClassSource;
use tests\NullDev\ContainerSupportedTestCase;
use tests\NullDev\Skeleton\CodeGenerator\SeniorDeveloperProvider;

/**
* @covers \NullDev\PhpSpecSkeleton\SpecGenerator
* @group nemesis
* @group codeGeneration
*/
class SpecGeneratorTest extends PHPUnit_Framework_TestCase
class SpecGeneratorTest extends ContainerSupportedTestCase
{
/** @var SpecGenerator */
private $specGenerator;
/** @var PhpParserGenerator */
private $phpParserGenerator;

public function setUp(): void
{
$this->specGenerator = SpecGenerator::default();
$this->specGenerator = $this->getService(SpecGenerator::class);
$this->phpParserGenerator = $this->getService(PhpParserGenerator::class);
}

public function testNothing(): void
/**
* @dataProvider provideTestRenderData
*/
public function testNothing(ImprovedClassSource $classSource, string $outputName): void
{
$this->markTestIncomplete('Auto generated using nemesis');
$test = $this->specGenerator->generate($classSource);

$this->assertSame($this->getFileContent($outputName), $this->phpParserGenerator->getOutput($test));
}

public function provideTestRenderData(): array
{
$provider = new SeniorDeveloperProvider();

return [
[new ImprovedClassSource($provider->provideClassType()), 'class-spec'],
[$provider->provideSourceWithParent(), 'class-with-parent-spec'],
[$provider->provideSourceWithInterface(), 'class-with-interface-spec'],
[$provider->provideSourceWithTrait(), 'class-with-trait-spec'],
[$provider->provideSourceWithAll(), 'class-with-all-spec'],
[$provider->provideSourceWithAllMulti(), 'class-with-all-multi-spec'],
[$provider->provideSourceWithOneParamConstructor(), 'class-with-all-1-param-spec'],
[$provider->provideSourceWithTwoParamConstructor(), 'class-with-all-2-param-spec'],
[$provider->provideSourceWithThreeParamConstructor(), 'class-with-all-3-param-spec'],
[$provider->provideSourceWithOneClasslessParamConstructor(), 'class-with-all-1-classless-param-spec'],
[$provider->provideSourceWithOneTypeDeclarationParamConstructor(), 'class-with-all-1-scalartypes-param-spec'],
];
}

protected function getFileContent(string $fileName): string
{
return file_get_contents(__DIR__.'/example-outputs/'.$fileName.'.output');
}
}
21 changes: 21 additions & 0 deletions tests/NullDev/PhpSpecSkeleton/example-outputs/class-spec.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace spec\Developer;

use Developer\Senior;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith();
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace spec\Developer;

use Coder;
use Developer\Senior;
use Human\Person;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith($firstName = 'firstName');
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
$this->shouldHaveType(Coder::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
$this->getFirstName()->shouldReturn('firstName');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace spec\Developer;

use Coder;
use Developer\Senior;
use FirstName;
use Human\Person;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let(FirstName $firstName)
{
$this->beConstructedWith($firstName);
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
$this->shouldHaveType(Coder::class);
}
public function it_should_expose_constructor_arguments_via_getters(FirstName $firstName)
{
$this->getFirstName()->shouldReturn($firstName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace spec\Developer;

use Coder;
use Developer\Senior;
use Human\Person;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith($firstName = 'firstName');
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
$this->shouldHaveType(Coder::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
$this->getFirstName()->shouldReturn('firstName');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace spec\Developer;

use Coder;
use Developer\Senior;
use FirstName;
use Human\Person;
use LastName;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let(FirstName $firstName, LastName $lastName)
{
$this->beConstructedWith($firstName, $lastName);
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
$this->shouldHaveType(Coder::class);
}
public function it_should_expose_constructor_arguments_via_getters(FirstName $firstName, LastName $lastName)
{
$this->getFirstName()->shouldReturn($firstName);
$this->getLastName()->shouldReturn($lastName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace spec\Developer;

use Coder;
use Developer\Senior;
use FirstName;
use HR\Finances\Wage;
use Human\Person;
use LastName;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let(FirstName $firstName, LastName $lastName, Wage $amount)
{
$this->beConstructedWith($firstName, $lastName, $amount);
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
$this->shouldHaveType(Coder::class);
}
public function it_should_expose_constructor_arguments_via_getters(FirstName $firstName, LastName $lastName, Wage $amount)
{
$this->getFirstName()->shouldReturn($firstName);
$this->getLastName()->shouldReturn($lastName);
$this->getAmount()->shouldReturn($amount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace spec\Developer;

use Coder;
use Coder2;
use Developer\Senior;
use Human\Person;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith();
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
$this->shouldHaveType(Coder::class);
$this->shouldHaveType(Coder2::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace spec\Developer;

use Coder;
use Developer\Senior;
use Human\Person;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith();
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
$this->shouldHaveType(Coder::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace spec\Developer;

use Coder;
use Developer\Senior;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith();
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Coder::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace spec\Developer;

use Developer\Senior;
use Human\Person;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith();
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
$this->shouldHaveType(Person::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace spec\Developer;

use Developer\Senior;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SeniorSpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith();
}
public function it_is_initializable()
{
$this->shouldHaveType(Senior::class);
}
public function it_should_expose_constructor_arguments_via_getters()
{
}
}

0 comments on commit 1275f0c

Please sign in to comment.