Completed
Push — master ( 31758c...fcf74b )
by Aimeos
08:54
created

ComposeTest::testCallUnknown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 */
7
8
9
namespace Aimeos\MW\View;
10
11
12
class ComposeTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
	private $translate;
16
17
18
	protected function setUp()
19
	{
20
		$engines = array(
21
			'.php' => new \Aimeos\MW\View\Standard( array( __DIR__ => array( '_testfiles' . DIRECTORY_SEPARATOR . 'php' ) ) ),
22
			'.phtml' => new \Aimeos\MW\View\Standard( array( __DIR__ => array( '_testfiles' . DIRECTORY_SEPARATOR . 'phtml' ) ) ),
23
		);
24
25
		$this->object = new \Aimeos\MW\View\Compose( $engines );
26
		$this->translate = new \Aimeos\MW\View\Helper\Translate\Standard( $this->object, new \Aimeos\MW\Translation\None( 'en_GB' ) );
27
	}
28
29
30
	protected function tearDown()
31
	{
32
		unset( $this->object, $this->translate );
33
	}
34
35
36
	public function testMagicMethods()
37
	{
38
		$this->assertEquals( false, isset( $this->object->test ) );
39
40
		$this->object->test = 10;
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Aimeos\MW\View\Compose>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
41
		$this->assertEquals( 10, $this->object->test );
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Aimeos\MW\View\Compose>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
42
		$this->assertEquals( true, isset( $this->object->test ) );
43
44
		unset( $this->object->test );
45
		$this->assertEquals( false, isset( $this->object->test ) );
46
47
		$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' );
48
		$this->object->test;
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Aimeos\MW\View\Compose>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
49
	}
50
51
52
	public function testGet()
53
	{
54
		$this->assertEquals( null, $this->object->get( 'test' ) );
55
		$this->assertEquals( 1, $this->object->get( 'test', 1 ) );
56
57
		$this->object->test = 10;
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Aimeos\MW\View\Compose>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
58
		$this->assertEquals( 10, $this->object->get( 'test' ) );
59
60
		$this->object->test = array( 'key' => 'val' );
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Aimeos\MW\View\Compose>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
		$this->assertEquals( 'val', $this->object->get( 'test/key' ) );
62
63
		$this->object->test = new \stdClass();
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Aimeos\MW\View\Compose>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64
		$this->assertEquals( null, $this->object->get( 'test/key' ) );
65
	}
66
67
68
	public function testCallCreateHelper()
69
	{
70
		$enc = $this->object->encoder();
71
		$this->assertInstanceOf( '\\Aimeos\\MW\\View\\Helper\\Iface', $enc );
72
	}
73
74
75
	public function testCallInvalidName()
76
	{
77
		$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' );
78
		$this->object->invalid();
79
	}
80
81
82
	public function testCallUnknown()
83
	{
84
		$this->setExpectedException( '\\Aimeos\\MW\\View\\Exception' );
85
		$this->object->unknown();
86
	}
87
88
89
	public function testCallAddHelper()
90
	{
91
		$this->object->addHelper( 'translate', $this->translate );
92
		$this->assertEquals( 'File', $this->object->translate( 'test', 'File', 'Files', 1 ) );
93
	}
94
95
96
	public function testAssignRender()
97
	{
98
		$this->object->addHelper( 'translate', $this->translate );
99
100
		$ds = DIRECTORY_SEPARATOR;
101
		$phpList = array( 'notexisting', __DIR__ . $ds . '_testfiles' . $ds . 'php' . $ds . 'template.php' );
102
		$phtmlList = array( 'notexisting', __DIR__ . $ds . '_testfiles' . $ds . 'phtml' . $ds . 'template.phtml' );
103
104
105
		$this->object->assign( array( 'quantity' => 1 ) );
106
		$output = $this->object->render( $phpList );
0 ignored issues
show
Documentation introduced by
$phpList is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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...
107
108
		$expected = "Number of files:\n1 File";
109
		$this->assertEquals( $expected, $output );
110
111
112
		$this->object->assign( array( 'quantity' => 0 ) );
113
		$output = $this->object->render( $phtmlList );
0 ignored issues
show
Documentation introduced by
$phtmlList is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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...
114
115
		$expected = "Number of directories:\n0 Files";
116
		$this->assertEquals( $expected, $output );
117
	}
118
119
120
	public function testAssignRenderRelativePath()
121
	{
122
		$this->object->addHelper( 'translate', $this->translate );
123
124
125
		$this->object->assign( array( 'quantity' => 1 ) );
126
		$output = $this->object->render( array( 'notexisting', 'template.php' ) );
0 ignored issues
show
Documentation introduced by
array('notexisting', 'template.php') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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...
127
128
		$expected = "Number of files:\n1 File";
129
		$this->assertEquals( $expected, $output );
130
131
132
		$this->object->assign( array( 'quantity' => 0 ) );
133
		$output = $this->object->render( array( 'notexisting', 'template.phtml' ) );
0 ignored issues
show
Documentation introduced by
array('notexisting', 'template.phtml') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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...
134
135
		$expected = "Number of directories:\n0 Files";
136
		$this->assertEquals( $expected, $output );
137
	}
138
}
139