-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
CustomRepositoryTest.php
57 lines (48 loc) · 1.39 KB
/
CustomRepositoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Spatie\Sheets\Tests\Integration;
use Illuminate\Support\Collection;
use Spatie\Sheets\Repository;
use Spatie\Sheets\Sheet;
use Spatie\Sheets\Sheets;
class CustomRepositoryTest extends TestCase
{
/** @test */
public function it_can_maintain_a_collection_with_a_custom_repository()
{
$documents = $this->app->make(Sheets::class)->all();
$this->assertInstanceOf(Collection::class, $documents);
$this->assertCount(2, $documents);
$this->assertContainsOnlyInstancesOf(Sheet::class, $documents);
$this->assertEquals('foo', $documents[0]->path);
$this->assertEquals('bar', $documents[0]->foo);
$this->assertEquals('bar', $documents[1]->path);
$this->assertEquals('bar', $documents[1]->foo);
}
protected function getEnvironmentSetUp($app)
{
$app['config']->set('sheets', [
'collections' => [
'null' => [
'repository' => StaticRepository::class,
],
],
]);
}
}
final class StaticRepository implements Repository
{
public function all(): Collection
{
return new Collection([
$this->get('foo'),
$this->get('bar'),
]);
}
public function get(string $path): ?Sheet
{
return new Sheet([
'path' => $path,
'foo' => 'bar',
]);
}
}