Passed
Push — master ( 240c83...03f39b )
by Mathias
06:41
created

Version36Test   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 42
dl 0
loc 89
rs 10
c 1
b 0
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testInfo() 0 5 1
A testOnFailedMigration() 0 10 1
A setUp() 0 18 1
A testExecutorThrowsException() 0 10 1
A testSuccesfullyMigrate() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yawik\Migration\Tests\Migrator;
6
7
use Iterator;
8
use Jean85\Version;
9
use MongoDB\Client;
10
use MongoDB\GridFS\Bucket;
11
use Yawik\Migration\Contracts\ProcessorInterface;
12
use Yawik\Migration\Exception\MigrationException;
13
use Yawik\Migration\Migrator\Version36\UserImageProcessor;
0 ignored issues
show
Bug introduced by
The type Yawik\Migration\Migrator...on36\UserImageProcessor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Auth\Service\UploadHandler as AuthHandler;
15
use Doctrine\ODM\MongoDB\DocumentManager;
16
use MongoDB\Database as MongoDatabase;
17
use PHPUnit\Framework\MockObject\MockObject;
18
use Psr\Container\ContainerInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Yawik\Migration\Migrator\Version36;
21
use PHPUnit\Framework\TestCase;
22
use Yawik\Migration\Tests\TestIterator;
23
use function MongoDB\with_transaction;
24
25
/**
26
 * Class Version36Test
27
 *
28
 * @covers \Yawik\Migration\Migrator\Version36
29
 * @package Migrator
30
 */
31
class Version36Test extends TestCase
32
{
33
    /**
34
     * @var MockObject|OutputInterface
35
     */
36
    private $out;
37
38
    /**
39
     * @var AuthHandler|MockObject
40
     */
41
    private $handler;
42
43
    /**
44
     * @var DocumentManager|MockObject
45
     */
46
    private $dm;
47
48
    /**
49
     * @var Version36
50
     */
51
    private Version36 $target;
52
    /**
53
     * @var MongoDatabase|MockObject
54
     */
55
    private $mongoDB;
56
57
58
    public function setUp(): void
59
    {
60
        $this->dm = $this->createMock(DocumentManager::class);
61
        $this->handler = $this->createMock(AuthHandler::class);
62
        $this->out = $this->createMock(OutputInterface::class);
63
        $this->mongoDB = $this->createMock(MongoDatabase::class);
64
        $container = $this->createMock(ContainerInterface::class);
65
66
        $container->method('get')
67
            ->willReturnMap([
68
                [DocumentManager::class, $this->dm],
69
                [AuthHandler::class, $this->handler],
70
                [OutputInterface::class, $this->out],
71
            ]);
72
73
        $this->dm->method('getDocumentDatabase')
74
            ->willReturn($this->mongoDB);
75
        $this->target = new Version36($this->dm, $this->out);
76
    }
77
78
    public function testInfo()
79
    {
80
        $target = $this->target;
81
        $this->assertSame("0.36.0", $target->version());
82
        $this->assertIsString($target->getDescription());
83
    }
84
85
    public function testSuccesfullyMigrate()
86
    {
87
        $target = $this->target;
88
        $processor = $this->createMock(ProcessorInterface::class);
89
90
        $target->addProcessor($processor);
91
        $processor->expects($this->once())
92
            ->method('process')
93
            ->willReturn(true);
94
95
        $this->assertTrue($target->migrate());
96
    }
97
98
    public function testOnFailedMigration()
99
    {
100
        $processor = $this->createMock(ProcessorInterface::class);
101
        $target = $this->target;
102
103
        $target->addProcessor($processor);
104
        $processor->expects($this->once())
105
            ->method('process')
106
            ->willReturn(false);
107
        $this->assertFalse($target->migrate());
108
    }
109
110
    public function testExecutorThrowsException()
111
    {
112
        $processor = $this->createMock(ProcessorInterface::class);
113
        $target = $this->target;
114
115
        $target->addProcessor($processor);
116
        $processor->expects($this->once())
117
            ->method('process')
118
            ->willThrowException(new MigrationException());
119
        $this->assertFalse($target->migrate());
120
    }
121
}