PHPExcelTest::testAdd()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Aimeos\MW\Container\Content;
4
5
6
/**
7
 * @license LGPLv3, http://www.gnu.org/licenses/lgpl.html
8
 * @copyright Metaways Infosystems GmbH, 2013
9
 * @copyright Aimeos (aimeos.org), 2015-2018
10
 */
11
class PHPExcelTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase 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...
12
{
13
	private $object;
14
15
16
	/**
17
	 * Sets up the fixture, for example, opens a network connection.
18
	 * This method is called before a test is executed.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function setUp()
23
	{
24
		if( !class_exists( '\PHPExcel' ) ) {
25
			$this->markTestSkipped( 'PHPExcel not available' );
26
		}
27
28
		$phpExcel = new \PHPExcel();
29
		$sheet = $phpExcel->createSheet();
30
31
		$this->object = new \Aimeos\MW\Container\Content\PHPExcel( $sheet, 'test', [] );
32
	}
33
34
35
	/**
36
	 * Tears down the fixture, for example, closes a network connection.
37
	 * This method is called after a test is executed.
38
	 *
39
	 * @access protected
40
	 */
41
	protected function tearDown()
42
	{
43
		unset( $this->object );
44
	}
45
46
47
	public function testClose()
48
	{
49
		$this->object->close();
50
	}
51
52
53
	public function testAdd()
54
	{
55
		$expected = array(
56
			array( 'test', 'file', 'data' ),
57
			array( '":;,"', pack( 'x' ), '\\' ),
58
		);
59
60
		foreach( $expected as $entry ) {
61
			$this->object->add( $entry );
62
		}
63
64
		$actual = $this->object->getResource()->toArray();
65
66
		$this->assertEquals( $expected, $actual );
67
	}
68
69
70
	public function testAddEmpty()
71
	{
72
		$expected = array(
73
			array( 'test', '', 'data' ),
74
		);
75
76
		foreach( $expected as $entry ) {
77
			$this->object->add( $entry );
78
		}
79
80
		$actual = $this->object->getResource()->toArray();
81
82
		$this->assertEquals( $expected, $actual );
83
	}
84
85
86
	public function testIterator()
87
	{
88
		$expected = array(
89
			array( 'test', 'file', 'data' ),
90
			array( 'foo', 'bar', 'baz' ),
91
			array( '":;,"', pack( 'x' ), '\\' ),
92
		);
93
94
		$this->object->getResource()->fromArray( $expected );
95
96
		$actual = [];
97
		foreach( $this->object as $key => $values ) {
98
			$actual[] = $values;
99
		}
100
101
		// $this->assertEquals( $expected, $actual ); // iterator doesn't work in 1.8.1
102
	}
103
104
105
	public function testIteratorEmpty()
106
	{
107
		$expected = array(
108
			array( 'test', '', 'data' ),
109
		);
110
111
		$this->object->getResource()->fromArray( $expected );
112
113
		$actual = [];
114
		foreach( $this->object as $values ) {
115
			$actual[] = $values;
116
		}
117
118
		$this->assertEquals( $expected, $actual );
119
	}
120
121
122
	public function testGetName()
123
	{
124
		$this->assertEquals( 'test', $this->object->getName() );
125
	}
126
127
128
	public function testGetResource()
129
	{
130
		$this->assertInstanceOf( '\PHPExcel_Worksheet', $this->object->getResource() );
131
	}
132
133
}
134