public function testGreetNameReturnsWorldWhenGeneratorIsBlank()
 {
     Phockito::when($this->nameGenerator)->generate()->return("");
     $actual = $this->testObj->greet();
     $expected = "Hello, World";
     Test::assertEqual($expected, $actual);
 }
Beispiel #2
0
<?php

require_once "../PUnit.php";
echo "Tautology: ";
Test::assertTrue(true);
Test::report();
echo "Multi with failure: ";
Test::assertEqual("abc", "123");
Test::assertEqual(12.3, 12.3);
Test::assertEqual(array("joe", "bloggs"), array("joe", "bloggs"));
Test::report();
echo "Deep array failure: ";
$expected = array("data" => true, "structure" => array("top" => 123, "left" => "abc"));
$actual = array("data" => true, "structure" => array("top" => 123, "left" => "abcde"));
Test::assertEqual($expected, $actual);
Test::report();
Test::end();
 public function testGreetAddsWorldWhenNameIsNotSpecified()
 {
     $expected = "Hello, World";
     $actual = $this->testObj->greet("");
     Test::assertEqual($expected, $actual);
 }
Beispiel #4
0
 public function assertFalse($actual)
 {
     return Test::assertEqual(false, $actual);
 }
Beispiel #5
0
 public static function runTests()
 {
     /**
      * TODO:
      * 1. Auto-create table
      * 2. Handle expiration date
      */
     $sql = "DROP TABLE IF EXISTS `%1\$s`;\nCREATE TABLE `%1\$s` (\n  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n  `created` datetime NOT NULL,\n  `modified` datetime DEFAULT NULL,\n  `expires` datetime DEFAULT NULL,\n  `hash` varchar(40) NOT NULL,\n  `key` text,\n  `value` longtext,\n  `used` int(11) unsigned NOT NULL DEFAULT '0',\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `hash` (`hash`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
     $model = new AppModel(0, false);
     $model->query(sprintf($sql, 'cache_test'));
     $model->query(sprintf($sql, 'cache_test2'));
     $cache = new AppModel(0, 'cache_test');
     $cache2 = new AppModel(0, 'cache_test2');
     Cache::config('default', array('engine' => 'DbTable', 'duration' => '+1 days', 'storage' => 'cache_test', 'lock' => false, 'serialize' => true));
     Cache::config('testcache2', array('engine' => 'DbTable', 'duration' => false, 'storage' => 'cache_test2', 'lock' => false, 'serialize' => true));
     App::uses('Test', 'Vendor');
     $key1 = 'testkey1';
     $key2 = 'testkey_2';
     $key3 = 'sometestkey3';
     $value1 = 'some value1';
     $value2 = 2;
     $value3 = array('key1' => 'value1', 'key2' => 'value_2');
     // Test 1 - read empty cache
     Test::assertEqual('Test1', array(null, null), array(Cache::read($key1), Cache::read($key3, 'testcache2')));
     // Test 2 - write cache on diff.configs
     $time = time();
     $dt = date('Y-m-d H:i:s', $time);
     $dt2 = date('Y-m-d H:i:s', $time + DAY);
     // Cache::write($key1, $value1);
     Cache::write($key2, $value2, 'testcache2');
     // Cache::write($key3, $value3);
     $trueRes = array(array(array('AppModel' => array('id' => '1', 'created' => $dt, 'modified' => $dt, 'expires' => $dt2, 'hash' => sha1($key1), 'key' => $key1, 'value' => serialize($value1), 'used' => '0')), array('AppModel' => array('id' => '2', 'created' => $dt, 'modified' => $dt, 'expires' => $dt2, 'hash' => sha1($key3), 'key' => $key3, 'value' => serialize($value3), 'used' => '0'))), array(array('AppModel' => array('id' => '1', 'created' => $dt, 'modified' => $dt, 'expires' => null, 'hash' => sha1($key2), 'key' => $key2, 'value' => serialize($value2), 'used' => '0'))));
     Test::assertEqual('Test2', $trueRes, array($cache->find('all'), $cache2->find('all')));
     /*
     $sql = 'DROP TABLE IF EXISTS `%s`';
     $model->query(sprintf($sql, 'cache_test'));
     $model->query(sprintf($sql, 'cache_test2'));
     */
 }