<?php describe('Vnn\\Services\\Location\\Google\\PlacesService', function () { beforeEach(function () { $this->places_api_key = "ENTER GOOGLE PLACES API KEY HERE"; }); describe('->getGooglePlaceAPIUrl()', function () { it('should return a properly encoded URL', function () { $service = new Vnn\Services\Location\Google\PlacesService(); $url = $service->getGooglePlaceAPIUrl("foo bar"); assert($url == "https://maps.googleapis.com/maps/api/place/textsearch/json?query=foo+bar&key="); $url = $service->getGooglePlaceAPIUrl("http://example.com?arg=value&arg2=value2"); assert($url == "https://maps.googleapis.com/maps/api/place/textsearch/json?query=http%3A%2F%2Fexample.com%3Farg%3Dvalue%26arg2%3Dvalue2&key="); }); }); // skip the test for actually looking up information xdescribe('->lookupLocation()', function () { it('should return a valid address, lat, and long', function () { $service = new Vnn\Services\Location\Google\PlacesService($this->places_api_key); $testAddress = "12002 Jones Maltsberger Rd 78216 TX"; $retVal = $service->lookupLocation($testAddress); assert($retVal['address'] == "12002 Jones Maltsberger Rd, San Antonio, TX 78216"); assert($retVal['lat'] == "29.5499212"); assert($retVal['lng'] == "-98.4652126"); $retVal = $service->lookupLocation($testAddress, true); assert($retVal['address'] == "12002 Jones Maltsberger Rd, San Antonio, TX 78216, USA"); }); }); });
/** * Create a pending context * * @param $description * @param callable $fn */ function xcontext($description, callable $fn) { xdescribe($description, $fn); }
public function tests() { PHPUsableTest::$current_test = $this; describe('with esperance style assertions', function ($test) { describe('with a true value', function ($test) { before(function ($test) { //Arbitratry variables can be stored on test to pass between blocks $test->my_value = true; }); it('should be true', function ($test) { $test->expect($test->my_value)->to->be->ok(); }); }); describe('with a false value', function ($test) { before(function ($test) { $test->my_value = false; }); it('should be false', function ($test) { $test->expect($test->my_value)->to->be(false); }); }); }); describe('with phpunit style assertions', function ($test) { describe('with a true value', function ($test) { before(function ($test) { $test->my_value = true; }); it('should be true', function ($test) { $test->assertTrue($test->my_value); }); }); describe('with a false value', function ($test) { before(function ($test) { $test->my_value = false; }); it('should be false', function ($test) { $test->assertFalse($test->my_value); }); }); }); describe('with mock expectations', function ($test) { before(function ($test) { $test->mock = $test->getMock('simple_mock', array('test_method')); $test->mock->expects($test->once())->method('test_method')->will($test->returnValue('hello world!')); }); it('should return the expected value', function ($test) { $test->assertEquals($test->mock->test_method(), 'hello world!'); }); it('should fail when it is not called', function ($test) { $test->markTestIncomplete('Some graceful manner needs to be found to indicate that this is expected to fail'); }); }); describe('with expected exceptions', function ($test) { it('should not error out', function ($test) { $test->setExpectedException('Exception'); throw new \Exception(); }); }); describe('disabled specs', function ($test) { it('should not get fatal, without test body'); xit('should not error out with xit', function ($test) { throw new \Exception(); }); describe('entry describe without body'); xdescribe('entry describe with x', function ($test) { it('should not error out with it', function ($test) { throw new \Exception(); }); describe('inner describe', function ($test) { it('should be also disabled', function ($test) { throw new \Exception(); }); }); describe('multiple inner describe', function ($test) { it('should be also disabled', function ($test) { throw new \Exception(); }); }); }); it('should not stack on disabled state', function ($test) { $test->assertTrue(true); }); it('should also mark incomplete when it does not have any expectation', function ($test) { }); }); describe('should use when method', function ($test) { when('there are several case with the same result', function ($test) { $test->assertTrue(true); }); }); }
}); it('should skip this test when invoked', function ($ctx) { skip(); }); it('should be strict about undefined variables', function ($ctx) { $arr = array(0); $result = $arr[0] + $arr[1]; }); // Nested blocks help organize tests and allow progressive augmentation of // test context. describe('Inner Block with Before All and Context Clobbering', function ($ctx) { before_all(function ($ctx) { // Do something costly like purge and re-seed a database. $ctx->purged_database = true; }); before(function ($ctx) { $ctx->admins = new Group('modified_admins'); }); it('should inherit context from outer before blocks', function ($ctx) { expect($ctx->bob)->to->be->a('Matura\\Test\\User'); }); it('should shadow context variables from outer contexts if assigned', function ($ctx) { expect($ctx->admins->name)->to->eql('modified_admins'); }); }); xdescribe('Skipped Block', function ($ctx) { it('should skip me because my block has been marked skipped', function ($ctx) { throw new Exception('I should not be invoked'); }); }); });