diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml deleted file mode 100644 index b24dced..0000000 --- a/.github/workflows/psalm.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Psalm - -on: - push: - paths: - - '**.php' - - 'psalm.xml' - -jobs: - psalm: - name: psalm - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Cache composer dependencies - uses: actions/cache@v1 - with: - path: vendor - key: composer-${{ hashFiles('composer.lock') }} - - - name: Run composer install - run: composer install -n --prefer-dist - - - name: Run psalm - run: ./vendor/bin/psalm -c psalm.xml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2a98a75..1b9b6a0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,20 +9,31 @@ jobs: fail-fast: true matrix: os: [ ubuntu-latest ] - php: [8.0, 8.1] - laravel: [ 8.*, 9.* ] + php: [ 8.1, 8.2, 8.3 ] + laravel: [ 8.*, 9.* , 10.*, 11.* ] dependency-version: [ prefer-lowest, prefer-stable ] include: - laravel: 8.* - testbench: 6.* + testbench: ^6.25 - laravel: 9.* testbench: 7.* + - laravel: 10.* + testbench: 8.* + - laravel: 11.* + testbench: 9.* + exclude: + - php: 8.1 + laravel: 11.* + - php: 8.2 + laravel: 8.* + - php: 8.3 + laravel: [8.*,9.*] name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Cache dependencies uses: actions/cache@v2 @@ -43,4 +54,4 @@ jobs: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - name: Execute tests - run: vendor/bin/phpunit + run: vendor/bin/pest diff --git a/.gitignore b/.gitignore index e9e2053..7667a6b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ coverage .idea .php_cs.cache .php-cs-fixer.cache - +.idea diff --git a/CHANGELOG.md b/CHANGELOG.md index 1704305..7bd4f2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,66 @@ All notable changes to `typescript-transformer` will be documented in this file +## 2.4.1 - 2024-05-03 + +### What's Changed + +* Let artisan handle the exceptions by @Tofandel in https://github.com/spatie/laravel-typescript-transformer/pull/41 +* + +**Full Changelog**: https://github.com/spatie/laravel-typescript-transformer/compare/2.4.0...2.4.1 + +## 2.4.0 - 2024-02-16 + +- Laravel 11 support + +**Full Changelog**: https://github.com/spatie/laravel-typescript-transformer/compare/2.3.2...2.4.0 + +## 2.3.2 - 2023-12-01 + +- Use Laravel typescript transformer by default (#34) +- Replace CarbonInterface with a string (#33) + +## 2.3.1 - 2023-10-12 + +- Replace CarbonInterface with a string (#33) + +## 2.3.0 - 2023-04-14 + +- Drop support for PHP 8.0 +- Enable collecting of enums by default + +## 2.2.0 - 2023-03-24 + +- Add a native enum transformer by default + +## 2.1.7 - 2023-01-24 + +### What's Changed + +- Refactor tests to pest by @AyoobMH in https://github.com/spatie/laravel-typescript-transformer/pull/18 +- Add Laravel 10 support by @njoguamos in https://github.com/spatie/laravel-typescript-transformer/pull/20 + +### New Contributors + +- @AyoobMH made their first contribution in https://github.com/spatie/laravel-typescript-transformer/pull/18 +- @njoguamos made their first contribution in https://github.com/spatie/laravel-typescript-transformer/pull/20 + +**Full Changelog**: https://github.com/spatie/laravel-typescript-transformer/compare/2.1.6...2.1.7 + +## 2.1.6 - 2022-11-18 + +- composer bump for typescript-transformer +- add test suite for php 8.2 + +## 2.1.5 - 2022-08-22 + +- do not fail when spatie/enum is not installed + +## 2.1.4 - 2022-08-22 + +- use package service provider to fix publishing config + ## 2.1.3 - 2022-01-25 ## What's Changed diff --git a/README.md b/README.md index 10747d1..fba52d4 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ This will be transformed to: ```ts export type User = { - int: number; + id: number; name: string; address: string | null; } diff --git a/composer.json b/composer.json index e668ff9..fa27ae6 100644 --- a/composer.json +++ b/composer.json @@ -16,21 +16,24 @@ } ], "require" : { - "php" : "^8.0", - "spatie/typescript-transformer" : "^2.1.3", - "illuminate/console" : "^8.69|^9.0" + "php": "^8.1", + "illuminate/console": "^8.83|^9.30|^10.0|^11.0", + "spatie/laravel-package-tools": "^1.12", + "spatie/typescript-transformer" : "^2.1.13" }, "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" + "mockery/mockery": "^1.4", + "nesbot/carbon": "^2.63", + "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0", + "pestphp/pest": "^1.22|^2.0", + "phpunit/phpunit": "^9.0|^10.0|^11.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|^2.0", + "spatie/phpunit-snapshot-assertions": "^4.2|^5.0", + "spatie/temporary-directory": "^1.2" }, "autoload" : { "psr-4" : { @@ -43,13 +46,15 @@ } }, "scripts" : { - "test" : "vendor/bin/phpunit", - "test-coverage" : "vendor/bin/phpunit --coverage-html coverage", - "psalm": "./vendor/bin/psalm -c psalm.xml", + "test" : "vendor/bin/pest", + "test-coverage" : "vendor/bin/pest --coverage", "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" : { diff --git a/config/typescript-transformer.php b/config/typescript-transformer.php index da8f5db..e96476c 100644 --- a/config/typescript-transformer.php +++ b/config/typescript-transformer.php @@ -13,11 +13,12 @@ /* * Collectors will search for classes in the `auto_discover_types` paths and choose the correct * transformer to transform them. By default, we include a DefaultCollector which will search - * for @typescript annotated and ![TypeScript] attributed classes to transform. + * for @typescript annotated and #[TypeScript] attributed classes to transform. */ 'collectors' => [ Spatie\TypeScriptTransformer\Collectors\DefaultCollector::class, + Spatie\TypeScriptTransformer\Collectors\EnumCollector::class, ], /* @@ -27,8 +28,9 @@ 'transformers' => [ Spatie\LaravelTypeScriptTransformer\Transformers\SpatieStateTransformer::class, + Spatie\TypeScriptTransformer\Transformers\EnumTransformer::class, Spatie\TypeScriptTransformer\Transformers\SpatieEnumTransformer::class, - Spatie\TypeScriptTransformer\Transformers\DtoTransformer::class, + Spatie\LaravelTypeScriptTransformer\Transformers\DtoTransformer::class, ], /* @@ -40,6 +42,7 @@ 'default_type_replacements' => [ DateTime::class => 'string', DateTimeImmutable::class => 'string', + Carbon\CarbonInterface::class => 'string', Carbon\CarbonImmutable::class => 'string', Carbon\Carbon::class => 'string', ], diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5141646..3f670dd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,21 @@ - - - - tests - - - - - src/ - - - - - - - - + + + + src/ + + + + + + + + + + tests + + + + + diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak new file mode 100644 index 0000000..5141646 --- /dev/null +++ b/phpunit.xml.dist.bak @@ -0,0 +1,28 @@ + + + + + tests + + + + + src/ + + + + + + + + + diff --git a/src/Commands/TypeScriptTransformCommand.php b/src/Commands/TypeScriptTransformCommand.php index b385727..f0aeb76 100644 --- a/src/Commands/TypeScriptTransformCommand.php +++ b/src/Commands/TypeScriptTransformCommand.php @@ -43,14 +43,14 @@ public function handle( try { $this->ensureConfiguredCorrectly(); - - $collection = $transformer->transform(); } catch (Exception $exception) { $this->error($exception->getMessage()); return 1; } + $collection = $transformer->transform(); + $this->table( ['PHP class', 'TypeScript entity'], collect($collection)->map(fn (TransformedType $type, string $class) => [ diff --git a/src/TypeScriptTransformerServiceProvider.php b/src/TypeScriptTransformerServiceProvider.php index d1d9d08..289ceee 100644 --- a/src/TypeScriptTransformerServiceProvider.php +++ b/src/TypeScriptTransformerServiceProvider.php @@ -3,33 +3,24 @@ namespace Spatie\LaravelTypeScriptTransformer; use Illuminate\Support\Arr; -use Illuminate\Support\ServiceProvider; +use Spatie\LaravelPackageTools\Package; +use Spatie\LaravelPackageTools\PackageServiceProvider; use Spatie\LaravelTypeScriptTransformer\Commands\TypeScriptTransformCommand; use Spatie\TypeScriptTransformer\TypeScriptTransformerConfig; use Spatie\TypeScriptTransformer\Writers\TypeDefinitionWriter; -class TypeScriptTransformerServiceProvider extends ServiceProvider +class TypeScriptTransformerServiceProvider extends PackageServiceProvider { - public function boot(): void + public function configurePackage(Package $package): void { - if ($this->app->runningInConsole()) { - $this->commands([ - TypeScriptTransformCommand::class, - ]); - } - - $this->publishes([ - __DIR__ . '/../config/typescript-transformer.php' => config_path('typescript-transformer.php'), - ]); + $package + ->name('laravel-typescript-transformer') + ->hasConfigFile() + ->hasCommand(TypeScriptTransformCommand::class); } - public function register(): void + public function packageRegistered(): void { - $this->mergeConfigFrom( - __DIR__ . '/../config/typescript-transformer.php', - 'typescript-transformer' - ); - $this->app->bind( TypeScriptTransformerConfig::class, fn () => TypeScriptTransformerConfig::create() diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..9ee7797 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,23 @@ +in('.'); + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +*/ + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +*/ diff --git a/tests/TestCase.php b/tests/TestCase.php index b1a0282..a3b5bb4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,11 +7,6 @@ class TestCase extends Orchestra { - public function setUp(): void - { - parent::setUp(); - } - protected function getPackageProviders($app) { return [ diff --git a/tests/Transformers/DtoTransformerTest.php b/tests/Transformers/DtoTransformerTest.php index 37d922a..c67a12e 100644 --- a/tests/Transformers/DtoTransformerTest.php +++ b/tests/Transformers/DtoTransformerTest.php @@ -1,44 +1,27 @@ 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(); +}); diff --git a/tests/Transformers/SpatieStateTransformerTest.php b/tests/Transformers/SpatieStateTransformerTest.php index 2fc9d27..984ee3a 100644 --- a/tests/Transformers/SpatieStateTransformerTest.php +++ b/tests/Transformers/SpatieStateTransformerTest.php @@ -1,54 +1,37 @@ 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(); +}); diff --git a/tests/TypeProcessors/LaravelCollectionTypeProcessorTest.php b/tests/TypeProcessors/LaravelCollectionTypeProcessorTest.php index 1d81d1c..20a2b1b 100644 --- a/tests/TypeProcessors/LaravelCollectionTypeProcessorTest.php +++ b/tests/TypeProcessors/LaravelCollectionTypeProcessorTest.php @@ -1,93 +1,75 @@ processor = new LaravelCollectionTypeProcessor(); - - $this->typeResolver = new TypeResolver(); - } - - /** @test */ - public function it_works_with_single_types() - { - $class = new class { - /** @var int[] */ - public Collection $propertyA; - - /** @var ?int[] */ - public Collection $propertyB; - - /** @var int[]|null */ - public ?Collection $propertyC; - - /** @var array */ - public Collection $propertyD; - - /** @var ?array */ - public ?Collection $propertyE; - - /** @var array|null */ - public ?Collection $propertyF; - - /** @var \Illuminate\Support\Collection */ - public Collection $propertyG; - - /** @var \Illuminate\Support\Collection|int[] */ - public Collection $propertyH; - - /** @var \Illuminate\Support\Collection|int[]|null */ - public ?Collection $propertyI; - }; - - $this->assertEquals('int[]', (string) $this->processType($class, 'propertyA')); - $this->assertEquals('?int[]', (string) $this->processType($class, 'propertyB')); - $this->assertEquals('int[]|null', (string) $this->processType($class, 'propertyC')); - $this->assertEquals('array', (string) $this->processType($class, 'propertyD')); - $this->assertEquals('?array', (string) $this->processType($class, 'propertyE')); - $this->assertEquals('array|null', (string) $this->processType($class, 'propertyF')); - $this->assertEquals('array', (string) $this->processType($class, 'propertyG')); - $this->assertEquals('int[]', (string) $this->processType($class, 'propertyH')); - $this->assertEquals('int[]|null', (string) $this->processType($class, 'propertyI')); - } - - /** @test */ - public function it_works_with_union_types() - { - $class = new class { - /** @var \Illuminate\Support\Collection|int[] */ - public Collection|array $property; - }; - - $this->assertEquals('int[]', (string) $this->processType($class, 'property')); - } - - private function processType(object $class, string $property): Type - { - $reflection = new ReflectionProperty($class, $property); - - return $this->processor->process( - TypeReflector::new($reflection)->reflectFromDocblock(), - $reflection, - new MissingSymbolsCollection() - ); - } + $reflection = new ReflectionProperty($class, $property); + + return test()->processor->process( + TypeReflector::new($reflection)->reflectFromDocblock(), + $reflection, + new MissingSymbolsCollection() + ); } + +beforeEach(function () { + $this->processor = new LaravelCollectionTypeProcessor(); + + $this->typeResolver = new TypeResolver(); +}); + +it('works with single types', function () { + $class = new class { + /** @var int[] */ + public Collection $propertyA; + + /** @var ?int[] */ + public Collection $propertyB; + + /** @var int[]|null */ + public ?Collection $propertyC; + + /** @var array */ + public Collection $propertyD; + + /** @var ?array */ + public ?Collection $propertyE; + + /** @var array|null */ + public ?Collection $propertyF; + + /** @var \Illuminate\Support\Collection */ + public Collection $propertyG; + + /** @var \Illuminate\Support\Collection|int[] */ + public Collection $propertyH; + + /** @var \Illuminate\Support\Collection|int[]|null */ + public ?Collection $propertyI; + }; + + expect((string) processType($class, 'propertyA'))->toEqual('int[]'); + expect((string) processType($class, 'propertyB'))->toEqual('?int[]'); + expect((string) processType($class, 'propertyC'))->toEqual('int[]|null'); + expect((string) processType($class, 'propertyD'))->toEqual('array'); + expect((string) processType($class, 'propertyE'))->toEqual('?array'); + expect((string) processType($class, 'propertyF'))->toEqual('array|null'); + expect((string) processType($class, 'propertyG'))->toEqual('array'); + expect((string) processType($class, 'propertyH'))->toEqual('int[]'); + expect((string) processType($class, 'propertyI'))->toEqual('int[]|null'); +}); + +it('works with union types', function () { + $class = new class { + /** @var \Illuminate\Support\Collection|int[] */ + public Collection|array $property; + }; + + expect((string) processType($class, 'property'))->toEqual('int[]'); +}); diff --git a/tests/TypescriptTransformerTest.php b/tests/TypescriptTransformerTest.php index 486fc52..7f50412 100644 --- a/tests/TypescriptTransformerTest.php +++ b/tests/TypescriptTransformerTest.php @@ -1,99 +1,74 @@ temporaryDirectory = (new TemporaryDirectory())->create(); - } +beforeEach(function () { + $this->temporaryDirectory = (new TemporaryDirectory())->create(); +}); - /** @test */ - public function it_will_register_the_config_correctly() - { - config()->set('typescript-transformer.auto_discover_types', 'fake-searching-path'); - config()->set('typescript-transformer.transformers', [SpatieStateTransformer::class]); - config()->set('typescript-transformer.output_file', 'index.d.ts'); - config()->set('typescript-transformer.writer', ModuleWriter::class); +it('will register the config correctly', function () { + config()->set('typescript-transformer.auto_discover_types', 'fake-searching-path'); + config()->set('typescript-transformer.transformers', [SpatieStateTransformer::class]); + config()->set('typescript-transformer.output_file', 'index.d.ts'); + config()->set('typescript-transformer.writer', ModuleWriter::class); - $config = resolve(TypeScriptTransformerConfig::class); + $config = resolve(TypeScriptTransformerConfig::class); - $this->assertEquals(['fake-searching-path'], $config->getAutoDiscoverTypesPaths()); - $this->assertEquals([new SpatieStateTransformer()], $config->getTransformers()); - $this->assertEquals('index.d.ts', $config->getOutputFile()); - $this->assertInstanceOf(ModuleWriter::class, $config->getWriter()); - } + expect($config->getAutoDiscoverTypesPaths())->toEqual(['fake-searching-path']); + expect($config->getTransformers())->toEqual([new SpatieStateTransformer()]); + expect($config->getOutputFile())->toEqual('index.d.ts'); + expect($config->getWriter())->toBeInstanceOf(ModuleWriter::class); +}); - /** @test */ - public function it_will_crash_if_an_older_version_of_searching_paths_was_defined() - { - config()->set('typescript-transformer.searching_path', 'fake-searching-path'); - config()->set('typescript-transformer.transformers', [SpatieStateTransformer::class]); - config()->set('typescript-transformer.output_file', 'index.d.ts'); +it('will crash if an older version of searching paths was defined', function () { + config()->set('typescript-transformer.searching_path', 'fake-searching-path'); + config()->set('typescript-transformer.transformers', [SpatieStateTransformer::class]); + config()->set('typescript-transformer.output_file', 'index.d.ts'); - $this->artisan('typescript:transform')->assertExitCode(1); - } + $this->artisan('typescript:transform')->assertExitCode(1); +}); - /** @test */ - public function it_can_transform_to_typescript() - { - config()->set('typescript-transformer.auto_discover_types', __DIR__ . '/FakeClasses'); - config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); +it('can transform to typescript', function () { + config()->set('typescript-transformer.auto_discover_types', __DIR__ . '/FakeClasses'); + config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); - $this->artisan('typescript:transform')->assertExitCode(0); + $this->artisan('typescript:transform')->assertExitCode(0); - $this->assertMatchesFileSnapshot($this->temporaryDirectory->path('index.d.ts')); - } + expect($this->temporaryDirectory->path('index.d.ts'))->toMatchFileSnapshot(); +}); - /** @test */ - public function it_can_define_the_input_path() - { - config()->set('typescript-transformer.searching_paths', __DIR__ . '/FakeClasses'); - config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); +it('can define the input path', function () { + config()->set('typescript-transformer.searching_paths', __DIR__ . '/FakeClasses'); + config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); - $this->artisan('typescript:transform --path='. __DIR__ . '/FakeClasses')->assertExitCode(0); + $this->artisan('typescript:transform --path='. __DIR__ . '/FakeClasses')->assertExitCode(0); - $this->assertMatchesFileSnapshot($this->temporaryDirectory->path('index.d.ts')); - } + expect($this->temporaryDirectory->path('index.d.ts'))->toMatchFileSnapshot(); +}); - /** @test */ - public function it_can_define_a_relative_input_path() - { - config()->set('typescript-transformer.searching_paths', __DIR__ . '/FakeClasses'); - config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); +it('can define a relative input path', function () { + config()->set('typescript-transformer.searching_paths', __DIR__ . '/FakeClasses'); + config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); - $this->app->useAppPath(__DIR__); - $this->app->setBasePath($this->temporaryDirectory->path('js')); + $this->app->useAppPath(__DIR__); + $this->app->setBasePath($this->temporaryDirectory->path('js')); - $this->artisan('typescript:transform --path=FakeClasses')->assertExitCode(0); + $this->artisan('typescript:transform --path=FakeClasses')->assertExitCode(0); - $this->assertMatchesFileSnapshot($this->temporaryDirectory->path('index.d.ts')); - } + expect($this->temporaryDirectory->path('index.d.ts'))->toMatchFileSnapshot(); +}); - /** @test */ - public function it_can_define_the_relative_output_path() - { - config()->set('typescript-transformer.searching_paths', __DIR__ . '/FakeClasses'); - config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); +it('can define the relative output path', function () { + config()->set('typescript-transformer.searching_paths', __DIR__ . '/FakeClasses'); + config()->set('typescript-transformer.output_file', $this->temporaryDirectory->path('index.d.ts')); - $this->app->useAppPath(__DIR__); - $this->app->setBasePath($this->temporaryDirectory->path()); + $this->app->useAppPath(__DIR__); + $this->app->setBasePath($this->temporaryDirectory->path()); - $this->artisan('typescript:transform --path=FakeClasses --output=other-index.d.ts')->assertExitCode(0); + $this->artisan('typescript:transform --path=FakeClasses --output=other-index.d.ts')->assertExitCode(0); - $this->assertMatchesFileSnapshot($this->temporaryDirectory->path('resources/other-index.d.ts')); - } -} + expect($this->temporaryDirectory->path('resources/other-index.d.ts'))->toMatchFileSnapshot(); +}); diff --git a/tests/__snapshots__/DtoTransformerTest__it_can_transform_a_dto__1.txt b/tests/__snapshots__/DtoTransformerTest__it_can_transform_a_dto__1.txt new file mode 100644 index 0000000..7ca3b15 --- /dev/null +++ b/tests/__snapshots__/DtoTransformerTest__it_can_transform_a_dto__1.txt @@ -0,0 +1,7 @@ +{ +other_dto_array: Array<{%Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\Dto\OtherDto%}>; +other_dto_collection: {%Spatie\TypeScriptTransformer\Tests\FakeClasses\Integration\OtherDtoCollection%}; +non_typed_laravel_collection: Array; +other_dto_laravel_collection: Array<{%Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\Dto\OtherDto%}>; +other_dto_laravel_eloquent_collection: Array<{%Spatie\LaravelTypeScriptTransformer\Tests\FakeClasses\Dto\OtherDto%}>; +} \ No newline at end of file