示例#1
0
 public function tests()
 {
     PHPUsableTest::$current_test = $this;
     describe('Arrays', function ($test) {
         describe('Merge', function ($test) {
             it('should not convert scalars to arrays', function ($test) {
                 $a = array('level 1' => array('level 2' => 2));
                 $b = array('level 1' => array('level 2' => 5));
                 $test->expect(array_replace_recursive($a, $b))->to->eql(array('level 1' => array('level 2' => 5)));
             });
             it('should unionize arrays', function ($test) {
                 $a = array('level 1' => array('level 2' => array(2, 3)));
                 $b = array('level 1' => array('level 2' => array(5)));
                 $test->expect(array_replace_recursive($a, $b))->to->eql(array('level 1' => array('level 2' => array(5, 3))));
             });
         });
         describe('Get', function ($test) {
             it('should get a single level value', function ($test) {
                 $arr = array('planets' => 'pluto');
                 $test->expect(Arrays::get($arr, 'planets'))->to->eql('pluto');
             });
             it('should get a multi level value', function ($test) {
                 $arr = array('milky_way' => array('planets' => array('earth')));
                 $test->expect(Arrays::get($arr, 'milky_way.planets'))->to->eql(array('earth'));
             });
             it('should return null for an undefined key', function ($test) {
                 $arr = array('milky_way' => array('planets' => array('earth')));
                 $test->expect(Arrays::get($arr, 'andromeda.planets'))->to->eql(null);
             });
         });
     });
 }
示例#2
0
 public function tests()
 {
     PHPUsableTest::$current_test = $this;
     describe('Profile', function ($test) {
         describe('run', function ($test) {
             it('should record memory usage', function ($test) {
                 $data = Profile::run(function () {
                 });
                 $test->assertArrayHasKey('memory before', $data);
                 $test->assertArrayHasKey('memory after', $data);
                 $test->assertArrayHasKey('memory peak', $data);
             });
             it('should record elapsed times', function ($test) {
                 $data = Profile::run(function () {
                 });
                 $test->assertArrayHasKey('elapsed', $data);
             });
             it('should record granular marks', function ($test) {
                 $data = Profile::run(function ($markFunc) {
                     $markFunc();
                     $markFunc();
                     $markFunc();
                 });
                 $test->assertArrayHasKey('marks', $data);
                 $test->assertEquals(3, count($data['marks']));
             });
         });
     });
 }
示例#3
0
 public function tests()
 {
     PHPUsableTest::$current_test = $this;
     describe('functions', function ($test) {
         describe('startsWith', function ($test) {
             it('should return true in the positive case', function ($test) {
                 $test->expect(Text::startsWith('helloWorld', 'hello'))->to->eql(true);
             });
             it('should return false in the negative case', function ($test) {
                 $test->expect(Text::startsWith('helloWorld', 'dfsf'))->to->eql(false);
             });
         });
         describe('endsWith', function ($test) {
             it('should return true in the positive case', function ($test) {
                 $test->expect(Text::endsWith('helloWorld', 'World'))->to->eql(true);
             });
             it('should return false in the negative case', function ($test) {
                 $test->expect(Text::endsWith('helloWorld', 'DWorld'))->to->eql(false);
             });
         });
         describe('ensureNoSuffix', function ($test) {
             it('removes a suffix if present', function ($test) {
                 $test->expect(Text::ensureNoSuffix('batman.jpg', '.jpg'))->to->eql('batman');
             });
             it('does nothing if suffix not present', function ($test) {
                 $test->expect(Text::ensureNoSuffix('batman.jpg', '.gif'))->to->eql('batman.jpg');
             });
             it('works in the degenerate case', function ($test) {
                 $test->expect(Text::ensureNoSuffix('b', 'b'))->to->eql('');
             });
         });
         describe('ensureNoPrefix', function ($test) {
             it('removes a prefix if present', function ($test) {
                 $test->expect(Text::ensureNoPrefix('batman.jpg', 'batman'))->to->eql('.jpg');
             });
             it('does nothing if prefix not present', function ($test) {
                 $test->expect(Text::ensureNoPrefix('batman.jpg', 'spiderman'))->to->eql('batman.jpg');
             });
             it('works in the degenerate case', function ($test) {
                 $test->expect(Text::ensureNoPrefix('b', 'b'))->to->eql('');
             });
         });
         describe('fromCamel', function ($test) {
             it('to convert to lower_case format', function ($test) {
                 $test->expect(Text::fromCamel("TestController"))->to->be("test_controller");
             });
         });
         describe('toCamel', function ($test) {
             it('should convert to camelCase', function ($test) {
                 $test->expect(Text::toCamel("test_controller"))->to->be("testController");
             });
             it('should convert to CamelCase if capitilization is specified', function ($test) {
                 $test->expect(Text::toCamel("test_controller", true))->to->be("TestController");
             });
         });
     });
 }
示例#4
0
 public function tests()
 {
     PHPUsableTest::$current_test = $this;
     describe('SchemaObject', function ($test) {
         it('should allow defined keys', function ($test) {
             $person_config = new PersonConfig();
             $person_config->first_name = 'Sparks';
             $person_config->age = new NaturalNumber(5);
             $person_condig->sign = 'aries';
             $test->expect($person_config->first_name)->to->eql('Sparks');
             $test->expect($person_config->age)->to->eql(new NaturalNumber(5));
         });
         it('should use defaults', function ($test) {
             $person_config = new PersonConfig();
             $test->expect($person_config->gender)->to->eql('M');
         });
         it('should throw when providing unexpected key/value pairs', function ($test) {
             $person_config = new PersonConfig();
             $test->expect(function () use($person_config) {
                 $person_config->weight = 150;
             })->to->throw('\\UnexpectedValueException');
         });
         it('should enforce types if specified', function ($test) {
             $person_config = new PersonConfig();
             $test->expect(function () use($person_config) {
                 $person_config->age = 5;
             })->to->throw('\\InvalidArgumentException');
             $test->expect(function () use($person_config) {
                 $person_config->sign = 'libra';
             })->to->throw('\\InvalidArgumentException');
         });
         it('should allows nulls when a class type is used', function ($test) {
             $person_config = new PersonConfig();
             $test->expect(function () use($person_config) {
                 $person_config->age = null;
             })->to->not->throw('\\Exception');
         });
         it('should ignore types if not specified', function ($test) {
             $person_config = new PersonConfig();
             $test->expect(function () use($person_config) {
                 $person_config->gender = 5;
                 $person_config->gender = 'M';
                 $person_config->gender = array();
             })->to->not->throw('\\Exception');
         });
     });
 }
function before()
{
    return \PHPUsable\PHPUsableTest::run_on_current_test('before', func_get_args());
}