Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit d6ae68c

Browse files
committed
Add tests for DTO
1 parent 855b597 commit d6ae68c

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"Saritasa\\Laravel\\Controllers\\": "src/"
2727
}
2828
},
29+
"autoload-dev": {
30+
"psr-4": { "Saritasa\\Laravel\\Controllers\\Tests\\": "tests/" }
31+
},
2932
"config": {
3033
"preferred-install": "dist",
3134
"sort-packages": true

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
processIsolation="false"
99
stopOnFailure="false"
1010
syntaxCheck="false"
11-
bootstrap="test/bootstrap.php"
11+
bootstrap="vendor/autoload.php"
1212
>
1313
<testsuites>
1414
<testsuite name="Saritasa Transformers Test Suite">

src/Responses/AddressDTO.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
use App\Models\Preference;
66
use Saritasa\Transformers\DtoModel;
77

8+
/**
9+
* Address
10+
*
11+
* @property-read string $name Person full name
12+
* @property-read string $address Street address
13+
* @property-read string $city City
14+
* @property-read string $state State
15+
* @property-read string $zip Zip Code
16+
*/
817
class AddressDTO extends DtoModel
918
{
1019
protected $name;
1120
protected $address;
1221
protected $city;
1322
protected $state;
1423
protected $zip;
15-
}
24+
}

tests/AddressDtoTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Saritasa\Laravel\Controllers\Tests;
4+
5+
use Saritasa\Laravel\Controllers\Responses\AddressDTO;
6+
7+
class AddressDtoTest extends TestCase
8+
{
9+
function testConstruct()
10+
{
11+
$address = new AddressDTO([
12+
'name' => 'Darth Vader',
13+
'address' => 'Capitans\'s Bridge',
14+
'city' => 'Death Star',
15+
'state' => 'Galaxy Empire',
16+
'zip' => '00001'
17+
]);
18+
19+
self::assertEquals('Darth Vader', $address->name);
20+
self::assertEquals('Capitans\'s Bridge', $address->address);
21+
self::assertEquals('Death Star', $address->city);
22+
self::assertEquals('Galaxy Empire', $address->state);
23+
self::assertEquals('00001', $address->zip);
24+
}
25+
}

tests/TestCase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Saritasa\Laravel\Controllers\Tests;
4+
5+
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
6+
7+
class TestCase extends PhpUnitTestCase
8+
{
9+
10+
/**
11+
* Creates the application.
12+
*
13+
* Needs to be implemented by subclasses.
14+
*
15+
* @return \Symfony\Component\HttpKernel\HttpKernelInterface
16+
*/
17+
public function createApplication()
18+
{
19+
$app = require __DIR__.'/../vendor/autoload.php';
20+
21+
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();
22+
23+
return $app;
24+
}
25+
}

0 commit comments

Comments
 (0)