|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace Spatie\LaravelTypeScriptTransformer\Tests\Transformers; |
4 | | - |
5 | | -use DateTime; |
6 | | -use ReflectionClass; |
7 | 3 | use Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\ChildState; |
8 | 4 | use Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\State; |
9 | | -use Spatie\LaravelTypeScriptTransformer\Tests\TestCase; |
10 | 5 | use Spatie\LaravelTypeScriptTransformer\Transformers\SpatieStateTransformer; |
11 | 6 |
|
12 | | -class SpatieStateTransformerTest extends TestCase |
13 | | -{ |
14 | | - private SpatieStateTransformer $transformer; |
15 | | - |
16 | | - public function setUp(): void |
17 | | - { |
18 | | - parent::setUp(); |
19 | | - |
20 | | - $this->transformer = new SpatieStateTransformer(); |
21 | | - } |
22 | | - |
23 | | - /** @test */ |
24 | | - public function it_will_only_convert_states() |
25 | | - { |
26 | | - $this->assertNotNull($this->transformer->transform( |
27 | | - new ReflectionClass(State::class), |
28 | | - 'State' |
29 | | - )); |
30 | | - |
31 | | - $this->assertNull($this->transformer->transform( |
32 | | - new ReflectionClass(ChildState::class), |
33 | | - 'State' |
34 | | - )); |
35 | | - |
36 | | - $this->assertNull($this->transformer->transform( |
37 | | - new ReflectionClass(DateTime::class), |
38 | | - 'State' |
39 | | - )); |
40 | | - } |
41 | | - |
42 | | - /** @test */ |
43 | | - public function it_can_transform_an_state() |
44 | | - { |
45 | | - $type = $this->transformer->transform( |
46 | | - new ReflectionClass(State::class), |
47 | | - 'FakeState' |
48 | | - ); |
49 | | - |
50 | | - $this->assertEquals("'child' | 'other_child'", $type->transformed); |
51 | | - $this->assertTrue($type->missingSymbols->isEmpty()); |
52 | | - $this->assertFalse($type->isInline); |
53 | | - } |
54 | | -} |
| 7 | +beforeEach(function () { |
| 8 | + $this->transformer = new SpatieStateTransformer(); |
| 9 | +}); |
| 10 | + |
| 11 | +it('will only convert states', function () { |
| 12 | + expect($this->transformer->transform( |
| 13 | + new ReflectionClass(State::class), |
| 14 | + 'State' |
| 15 | + ))->not->toBeNull(); |
| 16 | + |
| 17 | + expect($this->transformer->transform( |
| 18 | + new ReflectionClass(ChildState::class), |
| 19 | + 'State' |
| 20 | + ))->toBeNull(); |
| 21 | + |
| 22 | + expect($this->transformer->transform( |
| 23 | + new ReflectionClass(DateTime::class), |
| 24 | + 'State' |
| 25 | + ))->toBeNull(); |
| 26 | +}); |
| 27 | + |
| 28 | +it('can transform an state', function () { |
| 29 | + $type = $this->transformer->transform( |
| 30 | + new ReflectionClass(State::class), |
| 31 | + 'FakeState' |
| 32 | + ); |
| 33 | + |
| 34 | + expect($type->transformed)->toEqual("'child' | 'other_child'"); |
| 35 | + expect($type->missingSymbols->isEmpty())->toBeTrue(); |
| 36 | + expect($type->isInline)->toBeFalse(); |
| 37 | +}); |
0 commit comments