TdbmFluidSchemaTest::testExistingTable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\FluidSchema;
4
5
use Doctrine\DBAL\Schema\Schema;
6
use PHPUnit\Framework\TestCase;
7
8
class TdbmFluidSchemaTest extends TestCase
9
{
10
    public function testTable()
11
    {
12
        $schema = new Schema();
13
        $fluid = new TdbmFluidSchema($schema);
14
15
        $posts = $fluid->table('posts');
16
17
        $this->assertTrue($schema->hasTable('posts'));
18
19
        $this->assertSame($posts, $fluid->table('posts'), 'Failed asserting that the same instance is returned.');
20
    }
21
22
    public function testExistingTable()
23
    {
24
        $schema = new Schema();
25
        $postsSchemaTable = $schema->createTable('posts');
26
        $fluid = new TdbmFluidSchema($schema);
27
28
        $posts = $fluid->table('posts');
29
        $posts->column('foo');
30
31
        $this->assertTrue($postsSchemaTable->hasColumn('foo'));
32
    }
33
34
    public function testJunctionTable()
35
    {
36
        $schema = new Schema();
37
        $db = new TdbmFluidSchema($schema);
38
        $db->table('users')->id();
39
        $db->table('roles')->id();
40
        $db->junctionTable('users', 'roles');
41
42
        $this->assertTrue($schema->hasTable('users_roles'));
43
        $this->assertCount(2, $schema->getTable('users_roles')->getColumns());
0 ignored issues
show
Documentation introduced by
$schema->getTable('users_roles')->getColumns() is of type array<integer,object<Doc...ne\DBAL\Schema\Column>>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
        $this->assertNotNull($schema->getTable('users_roles')->getColumn('user_id'));
45
        $this->assertNotNull($schema->getTable('users_roles')->getColumn('role_id'));
46
    }
47
48
    public function testGetDbalSchema()
49
    {
50
        $schema = new Schema();
51
        $fluid = new TdbmFluidSchema($schema);
52
53
        $this->assertSame($schema, $fluid->getDbalSchema());
54
    }
55
}
56