function test_error() { assert_throws('CurlException', function () { $curl = new Curl(); $curl->get('diaewkaksdljf-invalid-url-dot-com.com'); }); }
function test_error_handler() { $class = __CLASS__ . '\\ErrorHandler'; $error_handler = function () { $context = array(); return Environmentalist::error_handler(0, 'message', 'file', 'line', $context); }; $handlers = function ($method) use($class) { return array(array($class, $method)); }; Environmentalist::set_error_handlers($handlers('exception_error_handler')); assert_throws('RuntimeException', $error_handler); Environmentalist::set_error_handlers($handlers('failing_error_handler')); $error_handler(); ensure($class::$failing_error_handler_called); Environmentalist::set_error_handlers($handlers('passing_error_handler')); $error_handler(); ensure($class::$passing_error_handler_called); }
assert_not_throws(function () use($p, $c) { $p->fire_death(); }); // check that params are passed through properly assert_equal($c->death_msg, 'I am dead inside'); // double slot $p->connect(Person::SIGNAL_READY, $c, Car::SLOT_OPEN_DOOR); $p->fire_internal_signal(); assert_equal($c->open_count, 3); // make sure __call isn't letting privates out assert_throws(function () use($p) { $p->emit(); }); // signals are inaccessible if called outside of their defined class or children assert_throws(function () use($p) { $p->ready(); }); //echo "\n....\n"; //$p->ready(); }; $A_TESTS['SignalSlot->disconnect'] = function () { $p = new Person(); $c = new Car(); $p->connect(Person::SIGNAL_READY, $c, Car::SLOT_OPEN_DOOR); $p->fire_internal_signal(); assert_equal($c->open_count, 1); $p->disconnect(Person::SIGNAL_READY, $c, Car::SLOT_OPEN_DOOR); $p->fire_internal_signal(); assert_equal($c->open_count, 1); // should be unaffected by call $p->connect(Person::SIGNAL_READY, $c, Car::SLOT_OPEN_DOOR);
public function test_throws() { assert_throws('FooException', function () { throw new FooException(); }); assert_fails(function () { assert_throws('FooException', function () { throw new Exception(); }); }); }
public function test_pattern_matching() { $this->def->add_pattern('/^(woof|arf)$/', 'return "dog";'); $this->def->add_pattern('/^(purr|meow)$/', 'return "cat";'); $this->with_class(function ($i, $r, $d) { assert_equal('dog', $i->woof()); assert_equal('dog', $i->arf()); assert_equal('cat', $i->purr()); assert_equal('cat', $i->meow()); assert_throws('\\Exception', function () use($i) { $i->raaaaaar(); }); }); }
assert_null($session->get('id')); }); it("saves and verifies data", function ($args) { $session = $args[0]; $session->set("id", "100"); $session->set("name", "fernyb"); $session->save(); $data = $session->session_store->session_data; $session_data = $session->session_store->verify($data); assert_equal($session_data["id"], "100"); assert_equal($session_data["name"], "fernyb"); assert_array_has_key($session_data, "session_id"); }); it("gets data after its saved", function ($args) { $session = $args[0]; $session->set("id", "100"); $session->set("name", "fernyb"); $session->save(); assert_equal($session->get("id"), "100"); assert_equal($session->get("name"), "fernyb"); }); it("does not save data when it overflows", function ($args) { $session = $args[0]; for ($i = 0; $i <= 94; $i++) { $session->set("svar_{$i}", "number: {$i}"); } assert_throws(CookieOverflow, function () use($session) { $session->save(); }, "Failed to throw CookieOverflow"); }); });
function test_super() { $struct = $this->struct; assert_throws('BadMethodCallException', function () use($struct) { $struct->super(); }); $struct->extend($this->assets)->extend($this->s3); assert_equal('http://example.s3.amazonaws.com/assets/test.png', $struct->asset_path('test.png')); assert_throws('BadMethodCallException', function () use($struct) { $struct->bad_super(); }); }