Completed
Push — 1.x ( 084efb...fac983 )
by Joel
02:47
created

ImageManagerTest::testPull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Docker\Tests\Manager;
4
5
use Docker\API\Model\AuthConfig;
6
use Docker\API\Model\BuildInfo;
7
use Docker\API\Model\CreateImageInfo;
8
use Docker\API\Model\PushImageInfo;
9
use Docker\Context\ContextBuilder;
10
use Docker\Manager\ImageManager;
11
use Docker\Tests\TestCase;
12
13
class ImageManagerTest extends TestCase
14
{
15
    /**
16
     * Return a container manager
17
     *
18
     * @return ImageManager
19
     */
20
    private function getManager()
21
    {
22
        return $this->getDocker()->getImageManager();
23
    }
24
25
    public function testBuildStream()
26
    {
27
        $contextBuilder = new ContextBuilder();
28
        $contextBuilder->from('ubuntu:precise');
29
        $contextBuilder->add('/test', 'test file content');
30
31
        $buildStream = $this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'test-image'], ImageManager::FETCH_STREAM);
32
33
        $this->assertInstanceOf('Docker\Stream\BuildStream', $buildStream);
34
35
        $lastMessage = "";
36
37
        $buildStream->onFrame(function (BuildInfo $frame) use (&$lastMessage) {
0 ignored issues
show
Bug introduced by
The method onFrame does only exist in Docker\Stream\BuildStream, but not in Psr\Http\Message\ResponseInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
38
            $lastMessage = $frame->getStream();
39
        });
40
        $buildStream->wait();
0 ignored issues
show
Bug introduced by
The method wait does only exist in Docker\Stream\BuildStream, but not in Psr\Http\Message\ResponseInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
41
42
        $this->assertContains("Successfully built", $lastMessage);
43
    }
44
45
    public function testBuildObject()
46
    {
47
        $contextBuilder = new ContextBuilder();
48
        $contextBuilder->from('ubuntu:precise');
49
        $contextBuilder->add('/test', 'test file content');
50
51
        $buildInfos = $this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'test-image'], ImageManager::FETCH_OBJECT);
52
53
        $this->assertInternalType('array', $buildInfos);
54
        $this->assertContains("Successfully built", $buildInfos[count($buildInfos) - 1]->getStream());
55
    }
56
57
    public function testCreateStream()
58
    {
59
        $createImageStream = $this->getManager()->create([
60
            'fromImage' => 'registry:latest'
61
        ], ImageManager::FETCH_STREAM);
62
63
        $this->assertInstanceOf('Docker\Stream\CreateImageStream', $createImageStream);
64
65
        $firstMessage = null;
66
67
        $createImageStream->onFrame(function (CreateImageInfo $createImageInfo) use (&$firstMessage) {
0 ignored issues
show
Bug introduced by
The method onFrame does only exist in Docker\Stream\CreateImageStream, but not in Psr\Http\Message\ResponseInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
68
            if (null === $firstMessage) {
69
                $firstMessage = $createImageInfo->getStatus();
70
            }
71
        });
72
        $createImageStream->wait();
0 ignored issues
show
Bug introduced by
The method wait does only exist in Docker\Stream\CreateImageStream, but not in Psr\Http\Message\ResponseInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
73
74
        $this->assertContains("Pulling from library/registry", $firstMessage);
75
    }
76
77
    public function testCreateObject()
78
    {
79
        $createImagesInfos = $this->getManager()->create([
80
            'fromImage' => 'registry:latest'
81
        ], ImageManager::FETCH_OBJECT);
82
83
        $this->assertInternalType('array', $createImagesInfos);
84
        $this->assertContains("Pulling from library/registry", $createImagesInfos[0]->getStatus());
85
    }
86
87
    public function testPushStream()
88
    {
89
        $contextBuilder = new ContextBuilder();
90
        $contextBuilder->from('ubuntu:precise');
91
        $contextBuilder->add('/test', 'test file content');
92
93
        $this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'localhost:5000/test-image'], ImageManager::FETCH_OBJECT);
94
95
        $registryConfig = new AuthConfig();
96
        $registryConfig->setServeraddress('localhost:5000');
97
        $pushImageStream = $this->getManager()->push('localhost:5000/test-image', [
98
            'X-Registry-Auth' => $registryConfig
99
        ], ImageManager::FETCH_STREAM);
100
101
        $this->assertInstanceOf('Docker\Stream\PushStream', $pushImageStream);
102
103
        $firstMessage = null;
104
105
        $pushImageStream->onFrame(function (PushImageInfo $pushImageInfo) use (&$firstMessage) {
0 ignored issues
show
Bug introduced by
The method onFrame does only exist in Docker\Stream\PushStream, but not in Psr\Http\Message\ResponseInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
106
            if (null === $firstMessage) {
107
                $firstMessage = $pushImageInfo->getStatus();
108
            }
109
        });
110
        $pushImageStream->wait();
0 ignored issues
show
Bug introduced by
The method wait does only exist in Docker\Stream\PushStream, but not in Psr\Http\Message\ResponseInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
111
112
        $this->assertContains("The push refers to a repository [localhost:5000/test-image]", $firstMessage);
113
    }
114
115
    public function testPushObject()
116
    {
117
        $contextBuilder = new ContextBuilder();
118
        $contextBuilder->from('ubuntu:precise');
119
        $contextBuilder->add('/test', 'test file content');
120
121
        $this->getManager()->build($contextBuilder->getContext()->read(), ['t' => 'localhost:5000/test-image'], ImageManager::FETCH_OBJECT);
122
123
        $registryConfig = new AuthConfig();
124
        $registryConfig->setServeraddress('localhost:5000');
125
        $pushImageInfos = $this->getManager()->push('localhost:5000/test-image', [
126
            'X-Registry-Auth' => $registryConfig
127
        ], ImageManager::FETCH_OBJECT);
128
129
        $this->assertInternalType('array', $pushImageInfos);
130
        $this->assertContains("The push refers to a repository [localhost:5000/test-image]", $pushImageInfos[0]->getStatus());
131
    }
132
}
133