Test Failed
Push — 1.0.0-dev ( 6506b5...225896 )
by nguereza
05:07
created

BackupAllTest::testCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 8
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php 
2
3
	use PHPUnit\Framework\TestCase;
4
5
	class BackupAllTest extends TestCase
6
	{	
7
	
8
		public static function setUpBeforeClass()
9
		{
10
			require 'hmvc/models/CoursModel.php';
11
			require 'hmvc/models/ClasseModel.php';
12
		}
13
		
14
		public static function tearDownAfterClass()
15
		{
16
                   
17
		}
18
                
19
               
20
	
21
		protected function setUp()
22
		{
23
                   
24
		}
25
26
		protected function tearDown()
27
		{
28
		}
29
30
		// tests
31
		public function testSomeFeature()
32
		{
33
			$config['driver']    =  'mysql';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $config = array(); before regardless.
Loading history...
34
			$config['username']  =  'root';
35
			$config['password']  =  '';
36
			$config['database']  =  'db_gesco';
37
			$config['hostname']  =  'localhost:3307';
38
			$config['charset']   = 'utf8';
39
			$config['collation'] = 'utf8_general_ci';
40
			$config['prefix']    =  '';
41
			$config['port']      =  3307;
42
			
43
			$l = new Log();
44
			$l->setLogger('TNHBIS');
45
			
46
			$db = new Database($config, $l);
47
			
48
			$b = new Benchmark();
49
			$db->setBenchmark($b);
50
			
51
			$c = new FileCache();
52
			$db->setCacheInstance($c);
53
			
54
			$db->cached(3000)->select('*')->from('etudiant')->getAll();
55
			
56
			//$db->setLogger($l);
57
			//file_put_contents('tnh.txt', stringfy_vars($db->getBenchmark()));
58
			$this->assertNotEmpty($db->getDatabaseConfiguration());
59
			$this->assertTrue($db->connect());
60
			
61
			
62
			
63
			$fv = new FormValidation();
64
			
65
			$this->assertFalse($fv->run());
66
			
67
			$m = new CoursModel($db);
68
			$m->setFormValidation($fv);
69
			$this->assertFalse($m->insert(array('dep_id' => 566, 'spe_lib' => '')));
70
			$this->assertFalse($m->getFormValidation()->run());
71
			
72
			$db = new Database();
73
			$db->setDatabaseConfiguration($config);
74
			$this->assertTrue($db->connect());
75
		}
76
		
77
		public function testCache()
78
		{
79
			$lf = new Log();
80
			$lf->setLogger('TNHCACHEFILE');
81
			$c = new FileCache();
82
			$c->setLogger($lf);
83
			//prevent using old data
84
			$c->clean();
85
			$this->assertFalse($c->get('foo'));
86
			$c->set('foo', 'bar');
87
			$this->assertEquals($c->get('foo'), 'bar');
88
			//class_loader('foo');
89
			//$this->expectOutputRegex('cannot');
90
		}
91
		
92
		
93
		
94
		
95
		public function testConfigChange(){
96
			//echo Config::get('base_url');
97
			$c = new Config();
98
			$c->set('base_url', 'foo');
99
			//echo get_config('base_url'); 
100
		}
101
		
102
		public function testCallPrivateProtectedMethod(){
103
			$c = new FileCache();
104
			$expected = CACHE_PATH . md5('foo') . '.cache';
105
			$result = runPrivateOrProtectedMethod($c, 'getFilePath', array('foo'));
106
			$this->assertEquals($expected, $result);
107
		}
108
		
109
		public function testMocks(){
110
			$mock = $this->getMockBuilder('Model')->getMock();
111
			$mock->expects($this->any())->method('get')->will($this->returnValue('foobar'));
112
			$this->assertEquals('foobar', $mock->get(1));
113
		}
114
	}