Completed
Pull Request — master (#12)
by
unknown
02:44
created

StandardTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A tearDown() 0 7 1
A testGetName() 0 4 1
A testGetDescription() 0 5 1
A testRun() 0 25 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2018
6
 */
7
8
9
namespace Aimeos\Controller\Jobs\Catalog\Export\Sitemap;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $context;
16
	private $aimeos;
17
18
19
	protected function setUp()
20
	{
21
		\Aimeos\MShop\Factory::setCache( true );
22
23
		$this->context = \TestHelperJobs::getContext();
24
		$this->aimeos = \TestHelperJobs::getAimeos();
25
26
		$this->object = new \Aimeos\Controller\Jobs\Catalog\Export\Sitemap\Standard( $this->context, $this->aimeos );
27
	}
28
29
30
	protected function tearDown()
31
	{
32
		\Aimeos\MShop\Factory::setCache( false );
33
		\Aimeos\MShop\Factory::clear();
34
35
		$this->object = null;
36
	}
37
38
39
	public function testGetName()
40
	{
41
		$this->assertEquals( 'Catalog site map', $this->object->getName() );
42
	}
43
44
45
	public function testGetDescription()
46
	{
47
		$text = 'Creates a catalog site map for search engines';
48
		$this->assertEquals( $text, $this->object->getDescription() );
49
	}
50
51
52
	public function testRun()
53
	{
54
		$this->context->getConfig()->set( 'controller/jobs/catalog/export/sitemap/max-items', 5 );
55
56
		$this->object->run();
57
58
		$ds = DIRECTORY_SEPARATOR;
59
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml.gz' );
60
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml.gz' );
61
		$this->assertFileExists( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml.gz' );
62
63
		$file1 = gzread( gzopen( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml.gz', 'rb' ), 0x1000 );
0 ignored issues
show
Unused Code introduced by
$file1 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
64
		$file2 = gzread( gzopen( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml.gz', 'rb' ), 0x1000 );
65
		$index = gzread( gzopen( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml.gz', 'rb' ), 0x1000 );
66
67
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-1.xml.gz' );
68
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-2.xml.gz' );
69
		unlink( 'tmp' . $ds . 'aimeos-catalog-sitemap-index.xml.gz' );
70
71
		$this->assertContains( 'Kaffee', $file2 );
72
		$this->assertContains( 'Tee', $file2 );
73
74
		$this->assertContains( 'aimeos-catalog-sitemap-1.xml.gz', $index );
75
		$this->assertContains( 'aimeos-catalog-sitemap-2.xml.gz', $index );
76
	}
77
}