1
|
|
|
<?php
|
|
|
|
|
2
|
|
|
Yii::import('ext.mainscript.creators.*');
|
3
|
|
|
Yii::import('ext.mainscript.helpers.*');
|
4
|
|
|
|
5
|
|
|
/**
|
6
|
|
|
* @author Nikita Melnikov <[email protected]>
|
7
|
|
|
* @date 26.09.12
|
8
|
|
|
* @package mainscript
|
9
|
|
|
*/
|
10
|
|
|
class PackedScriptCreatorTest extends CTestCase
|
11
|
|
|
{
|
12
|
|
|
public static function tearDownAfterClass()
|
13
|
|
|
{
|
14
|
|
|
ScriptsFileFinder::$root = dirname(__FILE__);
|
15
|
|
|
$creator = new PackedScriptCreator();
|
16
|
|
|
$creator->addScript('packed.js');
|
17
|
|
|
|
18
|
|
|
foreach($creator->getScriptList() as $file)
|
19
|
|
|
{
|
20
|
|
|
if( file_exists($file) )
|
21
|
|
|
unlink($file);
|
22
|
|
|
}
|
23
|
|
|
}
|
24
|
|
|
|
25
|
|
|
public function testCreateDelete()
|
26
|
|
|
{
|
27
|
|
|
ScriptsFileFinder::$root = dirname(__FILE__);
|
28
|
|
|
$creator = new PackedScriptCreator();
|
29
|
|
|
$creator->addScript('packed.js');
|
30
|
|
|
|
31
|
|
|
$this->assertFalse($creator->scripsExists());
|
32
|
|
|
|
33
|
|
|
$creator->create();
|
34
|
|
|
|
35
|
|
|
$this->assertTrue($creator->scripsExists());
|
36
|
|
|
|
37
|
|
|
$creator->delete();
|
38
|
|
|
|
39
|
|
|
$this->assertFalse($creator->scripsExists());
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
public function testUpdate()
|
43
|
|
|
{
|
44
|
|
|
ScriptsFileFinder::$root = dirname(__FILE__);
|
45
|
|
|
$creator = new PackedScriptCreator();
|
46
|
|
|
$creator->addScript('packed.js');
|
47
|
|
|
|
48
|
|
|
$this->assertFalse($creator->scripsExists());
|
49
|
|
|
|
50
|
|
|
$creator->update();
|
51
|
|
|
$this->assertTrue($creator->scripsExists());
|
52
|
|
|
}
|
53
|
|
|
|
54
|
|
|
public function testScriptsPath()
|
55
|
|
|
{
|
56
|
|
|
$creator = new PackedScriptCreator();
|
57
|
|
|
$creator->addScript('packed.js');
|
58
|
|
|
$creator->addScript('compiled.js');
|
59
|
|
|
$paths = array();
|
60
|
|
|
|
61
|
|
|
foreach( PackedScriptCreator::$scripts as $script )
|
62
|
|
|
{
|
63
|
|
|
$paths[] = ScriptsFileFinder::$root . $creator->path . $script;
|
64
|
|
|
}
|
65
|
|
|
|
66
|
|
|
$this->assertEquals($paths, $creator->getScriptList());
|
67
|
|
|
}
|
68
|
|
|
}
|
69
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.