Skip to content

Commit

Permalink
Merge pull request #18 from AyoobMH/refactor-tests-to-pest
Browse files Browse the repository at this point in the history
Refactor tests to pest
  • Loading branch information
freekmurze committed Dec 2, 2022
2 parents b8c1f42 + 57a8f71 commit f8a7e7d
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 259 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Expand Up @@ -43,4 +43,4 @@ jobs:
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
run: vendor/bin/pest
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -7,4 +7,4 @@ coverage
.idea
.php_cs.cache
.php-cs-fixer.cache

.idea
31 changes: 18 additions & 13 deletions composer.json
Expand Up @@ -22,17 +22,19 @@
"spatie/typescript-transformer" : "^2.1.12"
},
"require-dev" : {
"orchestra/testbench" : "^6.0|^7.0",
"mockery/mockery" : "^1.4",
"phpunit/phpunit" : "^9.0",
"spatie/temporary-directory" : "^1.2",
"spatie/phpunit-snapshot-assertions": "^4.2",
"spatie/data-transfer-object" : "^2.0",
"friendsofphp/php-cs-fixer": "^3.0",
"spatie/laravel-model-states" : "^1.6|^2.0",
"spatie/enum" : "^3.0",
"vimeo/psalm": "^4.2",
"nesbot/carbon" : "^2.63"
"mockery/mockery": "^1.4",
"nesbot/carbon": "^2.63",
"orchestra/testbench": "^6.0|^7.0",
"pestphp/pest": "^1.22",
"phpunit/phpunit": "^9.0",
"spatie/data-transfer-object": "^2.0",
"spatie/enum": "^3.0",
"spatie/laravel-model-states": "^1.6|^2.0",
"spatie/pest-plugin-snapshots": "^1.1",
"spatie/phpunit-snapshot-assertions": "^4.2",
"spatie/temporary-directory": "^1.2",
"vimeo/psalm": "^4.2"
},
"autoload" : {
"psr-4" : {
Expand All @@ -45,13 +47,16 @@
}
},
"scripts" : {
"test" : "vendor/bin/phpunit",
"test-coverage" : "vendor/bin/phpunit --coverage-html coverage",
"test" : "vendor/bin/pest",
"test-coverage" : "vendor/bin/pest --coverage",
"psalm": "./vendor/bin/psalm -c psalm.xml",
"format": "./vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"config" : {
"sort-packages" : true
"sort-packages" : true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra" : {
"laravel" : {
Expand Down
23 changes: 23 additions & 0 deletions tests/Pest.php
@@ -0,0 +1,23 @@
<?php

use Spatie\LaravelTypeScriptTransformer\Tests\TestCase;

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
*/

uses(TestCase::class)->in('.');

/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
*/

/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
*/
5 changes: 0 additions & 5 deletions tests/TestCase.php
Expand Up @@ -7,11 +7,6 @@

class TestCase extends Orchestra
{
public function setUp(): void
{
parent::setUp();
}

protected function getPackageProviders($app)
{
return [
Expand Down
55 changes: 19 additions & 36 deletions tests/Transformers/DtoTransformerTest.php
@@ -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();
});
79 changes: 31 additions & 48 deletions tests/Transformers/SpatieStateTransformerTest.php
@@ -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();
});

0 comments on commit f8a7e7d

Please sign in to comment.