TdbmDbProviderTest::testGetObjectExistingPk()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\TDBM\MetaHydrator;
4
5
6
use MetaHydrator\Exception\DBException;
7
use PHPUnit\Framework\TestCase;
8
use TheCodingMachine\TDBM\NoBeanFoundException;
9
use TheCodingMachine\TDBM\TDBMService;
10
11
class TdbmDbProviderTest extends TestCase
12
{
13 View Code Duplication
    public function testGetClassName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        $tdbmService = $this->createMock(TDBMService::class);
16
        $tdbmService->method('getBeanClassName')
17
            ->willReturn('App\Bean\Foo');
18
19
        $provider = new TdbmDbProvider($tdbmService);
20
21
        $this->assertSame('App\Bean\Foo', $provider->getClassName('foo'));
22
    }
23
24 View Code Duplication
    public function testGetObjectNoPk()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $tdbmService = $this->createMock(TDBMService::class);
27
        $tdbmService->method('_getPrimaryKeysFromObjectData')
28
            ->willReturn([]);
29
30
        $provider = new TdbmDbProvider($tdbmService);
31
32
33
34
        $this->assertNull($provider->getObject('foo', ['some_column_not_id'=>42]));
35
    }
36
37 View Code Duplication
    public function testGetObjectExistingPk()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $tdbmService = $this->createMock(TDBMService::class);
40
        $tdbmService->method('_getPrimaryKeysFromObjectData')
41
            ->willReturn(['id'=>42]);
42
43
        $tdbmService->method('findObjectByPk')
44
            ->willReturn('some_foo');
45
46
        $provider = new TdbmDbProvider($tdbmService);
47
48
49
50
        $this->assertSame('some_foo', $provider->getObject('foo', ['id'=>42]));
51
    }
52
53 View Code Duplication
    public function testGetObjectNonExistingPk()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $tdbmService = $this->createMock(TDBMService::class);
56
        $tdbmService->method('_getPrimaryKeysFromObjectData')
57
            ->willReturn(['id'=>'not_exist']);
58
59
        $tdbmService->method('findObjectByPk')
60
            ->willThrowException(new NoBeanFoundException('No bean found'));
61
62
        $provider = new TdbmDbProvider($tdbmService);
63
64
        $this->expectException(DBException::class);
65
        $this->expectExceptionMessage('No bean found');
66
67
        $provider->getObject('foo', ['id'=>'not_exist']);
68
    }
69
}
70