Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from AyoobMH/refactor-tests-to-pest
Refactor tests to pest
- Loading branch information
Showing
10 changed files
with
212 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ coverage | |
.idea | ||
.php_cs.cache | ||
.php-cs-fixer.cache | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use Spatie\LaravelTypeScriptTransformer\Tests\TestCase; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
uses(TestCase::class)->in('.'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,27 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelTypeScriptTransformer\Tests\Transformers; | ||
|
||
use ReflectionClass; | ||
use Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\Dto\Dto; | ||
use Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\Dto\OtherDto; | ||
use Spatie\LaravelTypeScriptTransformer\Tests\TestCase; | ||
use Spatie\LaravelTypeScriptTransformer\Transformers\DtoTransformer; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
use Spatie\TypeScriptTransformer\Tests\FakeClasses\Integration\OtherDtoCollection; | ||
use Spatie\TypeScriptTransformer\TypeScriptTransformerConfig; | ||
|
||
class DtoTransformerTest extends TestCase | ||
{ | ||
private DtoTransformer $transformer; | ||
|
||
use MatchesSnapshots; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->transformer = new DtoTransformer( | ||
resolve(TypeScriptTransformerConfig::class) | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_transform_a_dto() | ||
{ | ||
$type = $this->transformer->transform( | ||
new ReflectionClass(Dto::class), | ||
'FakeDto' | ||
); | ||
|
||
$this->assertMatchesSnapshot($type->transformed); | ||
$this->assertEquals([ | ||
OtherDto::class, | ||
OtherDtoCollection::class, | ||
], $type->missingSymbols->all()); | ||
$this->assertFalse($type->isInline); | ||
} | ||
} | ||
beforeEach(function () { | ||
$this->transformer = new DtoTransformer( | ||
resolve(TypeScriptTransformerConfig::class) | ||
); | ||
}); | ||
|
||
it('can transform a dto', function () { | ||
$type = $this->transformer->transform( | ||
new ReflectionClass(Dto::class), | ||
'FakeDto' | ||
); | ||
|
||
expect($type->transformed)->toMatchSnapshot(); | ||
expect([ | ||
OtherDto::class, | ||
OtherDtoCollection::class, | ||
])->toEqual($type->missingSymbols->all()); | ||
expect($type->isInline)->toBeFalse(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,37 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelTypeScriptTransformer\Tests\Transformers; | ||
|
||
use DateTime; | ||
use ReflectionClass; | ||
use Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\ChildState; | ||
use Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\State; | ||
use Spatie\LaravelTypeScriptTransformer\Tests\TestCase; | ||
use Spatie\LaravelTypeScriptTransformer\Transformers\SpatieStateTransformer; | ||
|
||
class SpatieStateTransformerTest extends TestCase | ||
{ | ||
private SpatieStateTransformer $transformer; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->transformer = new SpatieStateTransformer(); | ||
} | ||
|
||
/** @test */ | ||
public function it_will_only_convert_states() | ||
{ | ||
$this->assertNotNull($this->transformer->transform( | ||
new ReflectionClass(State::class), | ||
'State' | ||
)); | ||
|
||
$this->assertNull($this->transformer->transform( | ||
new ReflectionClass(ChildState::class), | ||
'State' | ||
)); | ||
|
||
$this->assertNull($this->transformer->transform( | ||
new ReflectionClass(DateTime::class), | ||
'State' | ||
)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_transform_an_state() | ||
{ | ||
$type = $this->transformer->transform( | ||
new ReflectionClass(State::class), | ||
'FakeState' | ||
); | ||
|
||
$this->assertEquals("'child' | 'other_child'", $type->transformed); | ||
$this->assertTrue($type->missingSymbols->isEmpty()); | ||
$this->assertFalse($type->isInline); | ||
} | ||
} | ||
beforeEach(function () { | ||
$this->transformer = new SpatieStateTransformer(); | ||
}); | ||
|
||
it('will only convert states', function () { | ||
expect($this->transformer->transform( | ||
new ReflectionClass(State::class), | ||
'State' | ||
))->not->toBeNull(); | ||
|
||
expect($this->transformer->transform( | ||
new ReflectionClass(ChildState::class), | ||
'State' | ||
))->toBeNull(); | ||
|
||
expect($this->transformer->transform( | ||
new ReflectionClass(DateTime::class), | ||
'State' | ||
))->toBeNull(); | ||
}); | ||
|
||
it('can transform an state', function () { | ||
$type = $this->transformer->transform( | ||
new ReflectionClass(State::class), | ||
'FakeState' | ||
); | ||
|
||
expect($type->transformed)->toEqual("'child' | 'other_child'"); | ||
expect($type->missingSymbols->isEmpty())->toBeTrue(); | ||
expect($type->isInline)->toBeFalse(); | ||
}); |
Oops, something went wrong.