PHPExcelTest::setUp()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Aimeos\MW\Container;
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
	protected function setUp()
14
	{
15
		if( !class_exists( '\PHPExcel' ) ) {
16
			$this->markTestSkipped( 'PHPExcel not available' );
17
		}
18
	}
19
20
21
	public function testExistingFile()
22
	{
23
		$filename = __DIR__ . DIRECTORY_SEPARATOR . 'excel5.xls';
24
25
		new \Aimeos\MW\Container\PHPExcel( $filename, 'Excel5', [] );
26
	}
27
28
29
	public function testNewFile()
30
	{
31
		$filename = __DIR__ . DIRECTORY_SEPARATOR . 'tempfile';
32
33
		$container = new \Aimeos\MW\Container\PHPExcel( $filename, 'Excel5', [] );
34
		$container->close();
35
36
		$result = file_exists( $container->getName() );
37
		unlink( $container->getName() );
38
39
		$this->assertTrue( $result );
40
		$this->assertEquals( '.xls', substr( $container->getName(), -4 ) );
41
		$this->assertFalse( file_exists( $container->getName() ) );
42
	}
43
44
45
	public function testFormat()
46
	{
47
		$container = new \Aimeos\MW\Container\PHPExcel( 'tempfile', 'Excel2007', [] );
48
		$this->assertEquals( '.xlsx', substr( $container->getName(), -5 ) );
49
50
		$container = new \Aimeos\MW\Container\PHPExcel( 'tempfile', 'OOCalc', [] );
51
		$this->assertEquals( '.ods', substr( $container->getName(), -4 ) );
52
53
		$container = new \Aimeos\MW\Container\PHPExcel( 'tempfile', 'CSV', [] );
54
		$this->assertEquals( '.csv', substr( $container->getName(), -4 ) );
55
	}
56
57
58
	public function testAdd()
59
	{
60
		$filename = __DIR__ . DIRECTORY_SEPARATOR . 'tempfile';
61
62
		$container = new \Aimeos\MW\Container\PHPExcel( $filename, 'Excel5', [] );
63
		$container->add( $container->create( 'test' ) );
64
65
		$result = 0;
66
		foreach( $container as $content ) {
67
			$result++;
68
		}
69
70
		$container->close();
71
		unlink( $container->getName() );
72
73
		$this->assertEquals( 1, $result );
74
	}
75
76
77
	public function testGet()
78
	{
79
		$filename = __DIR__ . DIRECTORY_SEPARATOR . 'excel5.xls';
80
		$container = new \Aimeos\MW\Container\PHPExcel( $filename, 'Excel5', [] );
81
82
		$this->assertInstanceOf( '\\Aimeos\\MW\\Container\\Content\\Iface', $container->get( 'Sheet2' ) );
83
84
		$this->setExpectedException( '\\Aimeos\\MW\\Container\\Exception' );
85
		$container->get( 'abc' );
86
	}
87
88
89
	public function testIterator()
90
	{
91
		$filename = __DIR__ . DIRECTORY_SEPARATOR . 'excel5.xls';
92
93
		$container = new \Aimeos\MW\Container\PHPExcel( $filename, 'Excel5', [] );
94
95
		$result = 0;
96
		foreach( $container as $key => $content ) {
97
			$result++;
98
		}
99
100
		$this->assertEquals( 3, $result );
101
	}
102
103
}
104