Skip to content

Commit 054a9b5

Browse files
committed
test: Add some initial tests
1 parent d74a675 commit 054a9b5

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"extra": {
8080
"laravel": {
8181
"providers": [
82-
"Articulate\\ArticulateServiceProvider"
82+
"Articulate\\Concise\\ConciseServiceProvider"
8383
],
8484
"facades": []
8585
}

src/Concise.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function getEntityMappers(): array
5959
return $this->entityMappers;
6060
}
6161

62+
/**
63+
* Get all component mappers
64+
*
65+
* @return array<class-string, \Articulate\Concise\Contracts\Mapper<*>>
66+
*/
67+
public function getComponentMappers(): array
68+
{
69+
return $this->componentMappers;
70+
}
71+
6272
/**
6373
* Registers the provided Mapper instance.
6474
*

tests/ConciseTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Articulate\Concise\Tests;
5+
6+
use App\Components\AuthCredentials;
7+
use App\Components\Timestamps;
8+
use App\Entities\User;
9+
use App\Mappers\Components\AuthCredentialsMapper;
10+
use App\Mappers\Components\TimestampsMapper;
11+
use App\Mappers\Entities\UserMapper;
12+
use App\Providers\MapperServiceProvider;
13+
use Articulate\Concise\Concise;
14+
use Articulate\Concise\ConciseServiceProvider;
15+
use PHPUnit\Framework\Attributes\Test;
16+
17+
class ConciseTest extends TestCase
18+
{
19+
protected function getPackageProviders($app)
20+
{
21+
return [
22+
MapperServiceProvider::class,
23+
];
24+
}
25+
26+
#[Test]
27+
public function serviceProviderHasBeenRegistered(): void
28+
{
29+
$this->assertTrue($this->app->providerIsLoaded(ConciseServiceProvider::class));
30+
}
31+
32+
#[Test]
33+
public function isBoundToTheContainer(): void
34+
{
35+
$this->assertTrue($this->app->bound(Concise::class));
36+
}
37+
38+
#[Test]
39+
public function hasRegisteredMappersSuccessfully(): void
40+
{
41+
$this->assertTrue($this->app->providerIsLoaded(MapperServiceProvider::class));
42+
43+
$concise = $this->app->make(Concise::class);
44+
45+
$entityMappers = $concise->getEntityMappers();
46+
47+
$this->assertNotEmpty($entityMappers);
48+
$this->assertCount(1, $entityMappers);
49+
$this->assertArrayHasKey(User::class, $entityMappers);
50+
$this->assertInstanceOf(UserMapper::class, $entityMappers[User::class]);
51+
52+
$componentMappers = $concise->getComponentMappers();
53+
54+
$this->assertNotEmpty($componentMappers);
55+
$this->assertCount(2, $componentMappers);
56+
$this->assertArrayHasKey(AuthCredentials::class, $componentMappers);
57+
$this->assertArrayHasKey(Timestamps::class, $componentMappers);
58+
$this->assertInstanceOf(AuthCredentialsMapper::class, $componentMappers[AuthCredentials::class]);
59+
$this->assertInstanceOf(TimestampsMapper::class, $componentMappers[Timestamps::class]);
60+
}
61+
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
abstract class TestCase extends OrchestraTestCase
99
{
10-
10+
protected $enablesPackageDiscoveries = true;
1111
}

0 commit comments

Comments
 (0)