Skip to content

Commit c073141

Browse files
committed
Remove model collision, improve test stability
1 parent 222eb54 commit c073141

File tree

6 files changed

+19
-36
lines changed

6 files changed

+19
-36
lines changed

tests/_support/DatabaseTestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ class DatabaseTestCase extends CIDatabaseTestCase
3737
public function setUp(): void
3838
{
3939
parent::setUp();
40-
40+
41+
cache()->clean();
42+
4143
// Configure and inject the Schemas service
4244
$config = new \Tatter\Schemas\Config\Schemas();
4345
$config->silent = false;
46+
$config->ignoredNamespaces = [];
4447

4548
$schemas = new \Tatter\Schemas\Schemas($config);
4649
Services::injectMock('schemas', $schemas);

tests/_support/Models/ArrayModel.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/_support/UnitTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function setUp(): void
1717
// Configure and inject the Schemas service
1818
$config = new \Tatter\Schemas\Config\Schemas();
1919
$config->silent = false;
20+
$config->ignoredNamespaces = [];
2021

2122
$schemas = new \Tatter\Schemas\Schemas($config);
2223
Services::injectMock('schemas', $schemas);

tests/entity/MagicTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class MagicTest extends DatabaseTestCase
1111
public function setUp(): void
1212
{
1313
parent::setUp();
14-
15-
$this->factories = new ArrayModel();
16-
$this->factory = new Factory($this->factories->find(1));
14+
15+
$this->row = $this->db->table('factories')->where('id', 1)->get()->getRowArray();
16+
$this->factory = new Factory($this->row);
1717

1818
$this->machines = new MachineModel();
1919
$this->machine = new Machine((array) $this->machines->with(false)->find(7));
@@ -26,12 +26,10 @@ public function testGetIgnoresUnmatched()
2626

2727
public function testRequiresProperties()
2828
{
29-
$row = $this->factories->find(1);
30-
3129
$this->expectException(RelationsException::class);
3230
$this->expectExceptionMessage('Class Tests\Support\Entities\Propertyless must have the table property to use relations');
3331

34-
$factory = (new Propertyless($row))->_getRelationship('foobar');
32+
$factory = (new Propertyless($this->row))->_getRelationship('foobar');
3533
}
3634

3735
public function testGetSuccess()

tests/entity/ManyMethodsTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class ManyMethodsTest extends DatabaseTestCase
99
public function setUp(): void
1010
{
1111
parent::setUp();
12-
13-
$this->factories = new ArrayModel();
14-
$this->factory = new Factory($this->factories->find(1));
12+
13+
$this->row = $this->db->table('factories')->where('id', 1)->get()->getRowArray();
14+
$this->factory = new Factory($this->row);
1515
}
1616

1717
public function testHasAnySuccess()
@@ -23,8 +23,9 @@ public function testHasAnySuccess()
2323

2424
public function testHasAnyFail()
2525
{
26-
$factory = new Factory($this->factories->find(4));
27-
$method = $this->getPrivateMethodInvoker($factory, '_has');
26+
$row = $this->db->table('factories')->where('id', 4)->get()->getRowArray();
27+
$factory = new Factory($row);
28+
$method = $this->getPrivateMethodInvoker($factory, '_has');
2829

2930
$this->assertFalse($method('workers'));
3031
}

tests/entity/RelationsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class RelationsTest extends DatabaseTestCase
1111
public function setUp(): void
1212
{
1313
parent::setUp();
14-
15-
$this->factories = new ArrayModel();
16-
$this->factory = new Factory($this->factories->find(1));
14+
15+
$this->row = $this->db->table('factories')->where('id', 1)->get()->getRowArray();
16+
$this->factory = new Factory($this->row);
1717
}
1818

1919
public function testUnknownTableFails()
@@ -80,7 +80,7 @@ public function testArrayHasMany()
8080
$servicers = new ServicerModel();
8181
$object = $servicers->with(false)->find(2);
8282
$servicer = new Servicer((array) $object);
83-
83+
8484
$lawyers = $servicer->relations('lawyers');
8585

8686
$this->assertCount(3, $lawyers);

0 commit comments

Comments
 (0)