Completed
Push — 1.x ( 1f27e1...92b96f )
by Joel
02:53
created

ContainerManagerTest::testFindAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
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\ContainerConfig;
6
use Docker\Manager\ContainerManager;
7
use Docker\Tests\TestCase;
8
9
class ContainerManagerTest extends TestCase
10
{
11
    /**
12
     * Return the container manager
13
     *
14
     * @return ContainerManager
15
     */
16
    private function getManager()
17
    {
18
        return self::getDocker()->getContainerManager();
19
    }
20
21
    /**
22
     * Be sure to have image before doing test
23
     */
24
    public static function setUpBeforeClass()
25
    {
26
        self::getDocker()->getImageManager()->create([
27
            'fromImage' => 'busybox:latest'
28
        ]);
29
    }
30
31
    public function testAttach()
32
    {
33
        $containerConfig = new ContainerConfig();
34
        $containerConfig->setImage('busybox:latest');
35
        $containerConfig->setCmd(['echo', '-n', 'output']);
36
        $containerConfig->setAttachStdout(true);
37
        $containerConfig->setLabels(new \ArrayObject(['docker-php-test' => 'true']));
38
39
        $containerCreateResult = $this->getManager()->create($containerConfig);
40
        $dockerRawStream = $this->getManager()->attach($containerCreateResult->getId(), [
0 ignored issues
show
Bug introduced by
The method getId does only exist in Docker\API\Model\ContainerCreateResult, 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
            'stream' => true,
42
            'stdout' => true,
43
        ], ContainerManager::FETCH_STREAM);
44
45
        $stdoutFull = "";
46
        $dockerRawStream->onStdout(function ($stdout) use (&$stdoutFull) {
0 ignored issues
show
Bug introduced by
The method onStdout does only exist in Docker\Stream\DockerRawStream, 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...
47
            $stdoutFull .= $stdout;
48
        });
49
50
        $this->getManager()->start($containerCreateResult->getId());
0 ignored issues
show
Bug introduced by
The method getId does only exist in Docker\API\Model\ContainerCreateResult, 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...
51
        $this->getManager()->wait($containerCreateResult->getId());
52
53
        $dockerRawStream->wait();
0 ignored issues
show
Bug introduced by
The method wait does only exist in Docker\Stream\DockerRawStream, 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...
54
55
        $this->assertEquals("output", $stdoutFull);
56
    }
57
58
    public function testAttachWebsocket()
59
    {
60
        $containerConfig = new ContainerConfig();
61
        $containerConfig->setImage('ubuntu:precise');
62
        $containerConfig->setCmd(['sh']);
63
        $containerConfig->setAttachStdout(true);
64
        $containerConfig->setAttachStderr(true);
65
        $containerConfig->setAttachStdin(false);
66
        $containerConfig->setOpenStdin(true);
67
        $containerConfig->setTty(true);
68
        $containerConfig->setLabels(new \ArrayObject(['docker-php-test' => 'true']));
69
70
        $containerCreateResult = $this->getManager()->create($containerConfig);
71
        $webSocketStream       = $this->getManager()->attachWebsocket($containerCreateResult->getId(), [
0 ignored issues
show
Bug introduced by
The method getId does only exist in Docker\API\Model\ContainerCreateResult, 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...
72
            'stream' => true,
73
            'stdout' => true,
74
            'stderr' => true,
75
            'stdin'  => true,
76
        ], ContainerManager::FETCH_STREAM);
77
78
        $this->getManager()->start($containerCreateResult->getId());
79
80
        // Read the bash first line
81
        $webSocketStream->read();
0 ignored issues
show
Bug introduced by
The method read does only exist in Docker\Stream\AttachWebsocketStream, 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...
82
83
        // No output after that so it should be false
84
        $this->assertFalse($webSocketStream->read());
85
86
        // Write something to the container
87
        $webSocketStream->write("echo test\n");
0 ignored issues
show
Bug introduced by
The method write does only exist in Docker\Stream\AttachWebsocketStream, 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...
88
89
        // Test for echo present (stdin)
90
        $output = "";
91
92
        while (($data = $webSocketStream->read()) != false) {
93
            $output .= $data;
94
        }
95
96
        $this->assertContains("echo", $output);
97
98
        // Exit the container
99
        $webSocketStream->write("exit\n");
100
    }
101
}
102