Skip to content

Commit 4b129ae

Browse files
Merge pull request #22 from verbanent/hotfix/tests-after-config
Fixed unit tests after config feature
2 parents 558046e + 77f024a commit 4b129ae

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tests/Providers/BinaryUuidServiceProviderTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace Verbanent\Uuid\Test\Providers;
66

7+
use Illuminate\Config\Repository;
78
use Illuminate\Contracts\Foundation\Application;
89
use Illuminate\Database\MySqlConnection;
10+
use Illuminate\Support\ServiceProvider;
911
use Mockery;
1012
use PHPUnit\Framework\TestCase;
1113
use Verbanent\Uuid\Providers\BinaryUuidServiceProvider;
@@ -35,4 +37,41 @@ public function testBoot()
3537
$this->assertInstanceOf(BinaryUuidServiceProvider::class, $this->binaryUuidServiceProvider);
3638
$this->assertNull($this->binaryUuidServiceProvider->boot());
3739
}
40+
41+
public function testRegisterMergesConfig()
42+
{
43+
$config = new Repository([]);
44+
$app = Mockery::mock(Application::class);
45+
$app->shouldReceive('make')->with('config')->andReturn($config);
46+
47+
$provider = new BinaryUuidServiceProvider($app);
48+
$provider->register();
49+
50+
$this->assertSame('id', $config->get('binary-uuid.default_column'));
51+
}
52+
53+
public function testBootPublishesConfigWhenRunningInConsole()
54+
{
55+
$app = Mockery::mock(Application::class);
56+
$app->shouldReceive('runningInConsole')->andReturn(true);
57+
$app->shouldReceive('configPath')->with('binary-uuid.php')->andReturn('/tmp/binary-uuid.php');
58+
59+
$provider = new BinaryUuidServiceProvider($app);
60+
$provider->boot();
61+
62+
$paths = ServiceProvider::pathsToPublish(
63+
BinaryUuidServiceProvider::class,
64+
'binary-uuid-config'
65+
);
66+
67+
$this->assertNotEmpty($paths);
68+
$this->assertTrue(in_array('/tmp/binary-uuid.php', array_values($paths), true));
69+
}
70+
71+
protected function tearDown(): void
72+
{
73+
Mockery::close();
74+
ServiceProvider::$publishes = [];
75+
ServiceProvider::$publishGroups = [];
76+
}
3877
}

tests/Traits/BinaryIdSupportableTraitTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Verbanent\Uuid\Test\Traits;
66

7+
use Illuminate\Config\Repository;
8+
use Illuminate\Container\Container;
79
use PHPUnit\Framework\TestCase;
810
use Verbanent\Uuid\Exceptions\AccessedUnsetUuidPropertyException;
911
use Verbanent\Uuid\Test\Example\BinaryId\CatIdModel;
@@ -69,4 +71,21 @@ public function testEncodeUuid()
6971
$binaryUuid = HorseIdModel::encodeUuid($this->id);
7072
$this->assertEquals($this->binaryUuid, $binaryUuid);
7173
}
74+
75+
public function testDefaultUuidColumnFromConfig()
76+
{
77+
$previous = Container::getInstance();
78+
$container = new Container();
79+
$container->instance('config', new Repository([
80+
'binary-uuid' => ['default_column' => 'uuid'],
81+
]));
82+
Container::setInstance($container);
83+
84+
try {
85+
$model = new CatIdModel();
86+
$this->assertSame('uuid', $model->getUuidColumn());
87+
} finally {
88+
Container::setInstance($previous);
89+
}
90+
}
7291
}

0 commit comments

Comments
 (0)