Test Setup Failed
Push — master ( 3bfa70...333906 )
by Gabriel
13:19
created

testEmptyRecordLoadRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Nip\Records\Tests\Relations;
4
5
use Nip\Records\Collections\Collection;
6
use Nip\Records\RecordManager;
7
use Nip\Records\Relations\HasAndBelongsToMany;
8
use Nip\Records\Tests\Fixtures\Records\Books\Book;
9
use Nip\Records\Tests\Fixtures\Records\Books\Books;
10
use Nip\Records\Tests\Fixtures\Records\Shelves\Shelves;
11
12
/**
13
 * Class HasAndBelongsToManyTest
14
 * @package Nip\Records\Tests\Relations
15
 */
16
class HasAndBelongsToManyTest extends \Nip\Records\Tests\AbstractTest
17
{
18
    public function testTableNameGeneration()
19
    {
20
        $tableA = new RecordManager();
21
        $tableA->setTable('tableA');
22
23
        $tableB = new RecordManager();
24
        $tableB->setTable('tableB');
25
26
        $relation = new HasAndBelongsToMany();
27
        $relation->setManager($tableA);
28
        $relation->setWith($tableB);
29
        self::assertEquals('tableA_tableB', $relation->getTable());
30
31
        $relation = new HasAndBelongsToMany();
32
        $relation->setManager($tableB);
33
        $relation->setWith($tableA);
34
        self::assertEquals('tableA_tableB', $relation->getTable());
35
    }
36
37
    public function testEmptyRecordLoadRelation()
38
    {
39
        $record = new Book();
40
        $record->setManager(Books::instance());
41
42
        $relation = new HasAndBelongsToMany();
43
        $relation->setWith(Shelves::instance());
44
        $relation->setItem($record);
45
        $results = $relation->getResults();
46
        self::assertInstanceOf(Collection::class, $results);
47
        self::assertCount(0, $results);
48
    }
49
}
50