/** * @test */ public function shouldThrowExceptionWhenNotFoundSourceFileToMove() { //given $files = new Files(); //when CatchException::when($files)->move('/broken/path/file', '/broken/path/new_file'); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\Utilities\\FileNotFoundException'); }
/** * @test */ public function shouldCheckIsCodeEquals() { //given $object = new MyClass(); //when CatchException::when($object)->someMethodThatThrowsException(); //then CatchException::assertThat()->hasCode(555); }
/** * @test */ public function getShouldThrowExceptionOnNull() { //given $optional = Optional::fromNullable(null); //when CatchException::when($optional)->get(); //then CatchException::assertThat()->isInstanceOf('\\Exception'); }
/** * @test */ public function shouldThrowExceptionForNonExistingLanguage() { //given Config::overrideProperty('language')->with('xx'); $i18n = new I18n(); //when CatchException::when($i18n)->t('product.description'); //then CatchException::assertThat()->isInstanceOf('Exception'); }
/** * @test */ public function shouldThrowExceptionWhenIsNull() { //given $value = null; //when CatchException::when(new Validate())->isNotNull($value, 'Is null'); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\Utilities\\Validator\\ValidateException'); CatchException::assertThat()->hasMessage('Is null'); }
/** * @test */ public function shouldNotCallActionWhenInvalidCredentials() { //given $_SERVER['PHP_AUTH_USER'] = '******'; $_SERVER['PHP_AUTH_PW'] = 'invalid'; //when CatchException::when($this)->get('/auth_sample/index'); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\Api\\UnauthorizedException'); }
/** * @test */ public function shouldThrowExceptionOnExecutionError() { //given Mock::when($this->pdoMock)->errorInfo()->thenReturn(array('HY000', '20102', 'Execution error')); $executor = new PDOPreparedStatementExecutor(); //when CatchException::when($executor)->createPDOStatement($this->dbMock, 'sql', array(), 'sql string'); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\DbException'); }
/** * @test */ public function shouldFailIfModelsAreNotEqual() { //given $product = new Product(array('name' => 'abc')); $otherProduct = new Product(array('name' => 'abc')); $otherProduct->non_persistent_field = 'a'; //when CatchException::when(Assert::thatModel($product))->isEqualTo($otherProduct); //then CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException'); }
/** * @test */ public function shouldThrowExceptionWhenControllerNotFound() { //given $routeRule = new RouteRule('GET', '/simple_test/action', 'not_exists', 'action', false); $factory = $this->injector->getInstance('\\Ouzo\\ControllerFactory'); //when CatchException::when($factory)->createController($routeRule); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\ControllerNotFoundException'); CatchException::assertThat()->hasMessage('Controller [NotExists] for URI [/simple_test/action] does not exist!'); }
/** * @test */ public function shouldThrowConnectionExceptionFromForPostgres() { //given Config::overrideProperty('sql_dialect')->with('\\Ouzo\\Db\\Dialect\\PostgresDialect'); Mock::when($this->pdoMock)->errorInfo()->thenReturn(array('57P01', 7, 'Execution error')); $executor = StatementExecutor::prepare($this->dbMock, 'SELECT 1', array(), array()); //when CatchException::when($executor)->execute(); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\DbConnectionException'); Config::revertProperty('sql_dialect'); }
/** * @test */ public function runInTransactionShouldInvokeRollbackOnFailure() { // given Db::getInstance()->enableTransactions(); $dbHandle = Mock::mock(); $db = new Db(false); $db->_dbHandle = $dbHandle; //when CatchException::when($db)->runInTransaction(array(new Sample(), 'exceptionMethod')); //then CatchException::assertThat()->isInstanceOf('InvalidArgumentException'); Mock::verify($dbHandle)->beginTransaction(); Mock::verify($dbHandle)->neverReceived()->commitTransaction(); Mock::verify($dbHandle)->rollBack(); }
/** * @test */ public function shouldFailIfStringsAreEqualWhenTheyShouldNotBe() { CatchException::when(Assert::thatString("Frodo"))->isNotEqualTo('Frodo'); CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException'); }
/** * @test */ public function shouldThrowExceptionWhenVarNotDefinedForInject() { //when CatchException::when($this->injector)->getInstance('\\ClassWithInvalidDep'); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\Injection\\InjectorException'); }
/** * @test */ public function shouldThrowExceptionWhenObjectNotHaveCloseInNestedObject() { //given $parser = $this->parser('object $user { int $age object $role { int $id string $name }'); //when CatchException::when($parser)->S(); //then CatchException::assertThat()->isInstanceOf('\\WSDL\\Parser\\ParserException')->hasMessage('Missing close object'); }
/** * @test */ public function shouldNotValidateGetMethod() { //when CatchException::when($this)->get('/csrf_sample/index'); //then CatchException::assertThat()->notCaught(); }
private function _assertNot() { $args = func_get_args(); $method = array_shift($args); $array = array_shift($args); call_user_func_array(array(CatchException::when(Assert::thatArray($array)), $method), $args); CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException'); }
/** * @test */ public function shouldThrowExceptionWhenClassNotExists() { //given $annotationWSDLBuilder = new AnnotationWSDLBuilder('\\Non\\Exists\\Class'); //when CatchException::when($annotationWSDLBuilder)->build(); //then CatchException::assertThat()->hasMessage('Class [\\Non\\Exists\\Class] not exists'); }
/** * @test */ public function shouldNotFindRouteWhenExceptAction() { //given Route::allowAll('/users', 'users', array('except' => array('add'))); $router = $this->_createRouter('GET', '/users/add'); //when CatchException::when($router)->findRoute(); //then CatchException::assertThat(); }
/** * @test */ public function findByIdShould() { //when CatchException::when(new ModelWithoutPrimaryKey())->findById(1); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\DbException')->hasMessage('Primary key is not defined for table products'); }
/** * @test * @group sqlite3 */ public function shouldThrowExceptionIfAliasInUpdateQuery() { //when CatchException::when(Category::alias('c')->where(array('c.name' => 'old')))->update(array('name' => "new")); //then CatchException::assertThat()->isInstanceOf('\\InvalidArgumentException'); }
/** * @test */ public function shouldCallbackInvokeAfterInit() { //given $callback = array($this, '_afterInitCallback'); Config::overrideProperty('callback', 'afterControllerInit')->with($callback); Route::get('/sample/save', 'sample#save'); //when CatchException::when($this)->get('/sample/save'); //then CatchException::assertThat()->hasMessage("afterInitCallback"); }
/** * @test * @dataProvider notEqualToNull * @param $notNull */ public function shouldNotBeEqual($notNull) { CatchException::when(GeneralAssert::that(null))->isEqualTo($notNull); CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException'); }
/** * @test */ public function shouldThrowExceptionWhenFileAlreadyExists() { //given $generator = new Generator('products'); $fileName = '/tmp/example.php'; file_put_contents($fileName, ''); //when CatchException::when($generator)->saveToFile($fileName); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\Tools\\Model\\Template\\GeneratorException'); unlink($fileName); }
/** * @test */ public function shouldThrowExceptionIfFirstCalledForEmptyIterator() { //given $iterator = FluentIterator::fromArray(array()); // when CatchException::when($iterator)->first(); // then CatchException::assertThat()->isInstanceOf('\\InvalidArgumentException'); }
/** * @test */ public function shouldRenderAjaxViewWithoutViewName() { //given Route::allowAll('/simple_test', 'simple_test'); //when CatchException::when($this)->get('/simple_test/empty_view_name'); //then CatchException::assertThat()->isInstanceOf('\\Ouzo\\View\\ViewException'); }
/** * @test */ public function shouldFailForInvalidJson() { //given StreamStub::register('json'); StreamStub::$body = '{"name":"jonh","id":123,"ip":"127.0.0.1}'; ContentType::set('application/json'); //when CatchException::when($this)->getRequestParameters('json://input'); //then CatchException::assertThat()->isInstanceOf('Ouzo\\Utilities\\JsonDecodeException'); StreamStub::unregister(); }
/** * @test */ public function shouldStubMultipleCallsWithResultsAndExceptions() { //given $exception = new Exception("msg"); $mock = Mock::mock(); Mock::when($mock)->method()->thenReturn('result'); Mock::when($mock)->method()->thenThrow($exception); //when $result = $mock->method(); CatchException::when($mock)->method(); //then $this->assertEquals("result", $result); CatchException::assertThat()->isEqualTo($exception); }
/** * @test */ public function shouldInvokeFirstLastTieBreaker() { //given $tieBreaker2 = Functions::throwException(new Exception('second should be invoked')); $alwaysEqual = Functions::constant(0); $comparator = Comparator::compound($alwaysEqual, $alwaysEqual, $tieBreaker2); //when CatchException::when(new CallableWrapper($comparator))->call(null, null); //then CatchException::assertThat()->hasMessage('second should be invoked'); }
/** * @test */ public function shouldThrowExceptionWhenOccursUnexpectedCharacter() { //given $param = 'string [$message'; $tokenizer = new Tokenizer(); //when CatchException::when($tokenizer)->lex($param); //then CatchException::assertThat()->hasMessage('Unexpected character: >[< offset >7<'); }
/** * @test */ public function shouldThrowOnBatchInsert() { //given $previous = Config::getValue('sql_dialect'); Config::overrideProperty('sql_dialect')->with('Ouzo\\Db\\Dialect\\MySqlDialect'); $inserter = new BatchInserter(); $inserter->add(new Product(array('name' => 'product1'))); //when CatchException::when($inserter)->execute(); //then CatchException::assertThat()->hasMessage("Batch insert not supported in mysql")->isInstanceOf('InvalidArgumentException'); Config::overrideProperty('sql_dialect')->with($previous); }