コード例 #1
0
 public function __call($method, $args)
 {
     try {
         call_user_func_array(array($this->object, $method), $args);
     } catch (Exception $exception) {
         CatchException::$exception = $exception;
     }
 }
コード例 #2
0
ファイル: CatchExceptionTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldCheckIsCodeEquals()
 {
     //given
     $object = new MyClass();
     //when
     CatchException::when($object)->someMethodThatThrowsException();
     //then
     CatchException::assertThat()->hasCode(555);
 }
コード例 #3
0
ファイル: FilesTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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');
 }
コード例 #4
0
ファイル: OptionalTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function getShouldThrowExceptionOnNull()
 {
     //given
     $optional = Optional::fromNullable(null);
     //when
     CatchException::when($optional)->get();
     //then
     CatchException::assertThat()->isInstanceOf('\\Exception');
 }
コード例 #5
0
ファイル: I18nTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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');
 }
コード例 #6
0
ファイル: ValidateTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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');
 }
コード例 #7
0
 /**
  * @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');
 }
コード例 #8
0
 /**
  * @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');
 }
コード例 #9
0
 /**
  * @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!');
 }
コード例 #10
0
ファイル: ModelAssertTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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');
 }
コード例 #11
0
 /**
  * @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');
 }
コード例 #12
0
ファイル: DbTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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();
 }
コード例 #13
0
ファイル: UriTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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();
 }
コード例 #14
0
ファイル: StringAssertTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldFailIfStringsAreEqualWhenTheyShouldNotBe()
 {
     CatchException::when(Assert::thatString("Frodo"))->isNotEqualTo('Frodo');
     CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException');
 }
コード例 #15
0
ファイル: InjectorTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldThrowExceptionWhenVarNotDefinedForInject()
 {
     //when
     CatchException::when($this->injector)->getInstance('\\ClassWithInvalidDep');
     //then
     CatchException::assertThat()->isInstanceOf('\\Ouzo\\Injection\\InjectorException');
 }
コード例 #16
0
ファイル: ParserTest.php プロジェクト: piotrooo/wsdl-creator
 /**
  * @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');
 }
コード例 #17
0
ファイル: CsrfProtectorTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldNotValidateGetMethod()
 {
     //when
     CatchException::when($this)->get('/csrf_sample/index');
     //then
     CatchException::assertThat()->notCaught();
 }
コード例 #18
0
ファイル: ArrayAssertTest.php プロジェクト: letsdrink/ouzo
 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');
 }
コード例 #19
0
 /**
  * @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');
 }
コード例 #20
0
ファイル: ComparatorTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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');
 }
コード例 #21
0
ファイル: ModelTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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');
 }
コード例 #22
0
 /**
  * @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');
 }
コード例 #23
0
ファイル: FluentIteratorTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldThrowExceptionIfFirstCalledForEmptyIterator()
 {
     //given
     $iterator = FluentIterator::fromArray(array());
     // when
     CatchException::when($iterator)->first();
     // then
     CatchException::assertThat()->isInstanceOf('\\InvalidArgumentException');
 }
コード例 #24
0
ファイル: MySqlDialectTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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);
 }
コード例 #25
0
ファイル: GeneratorTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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);
 }
コード例 #26
0
ファイル: MockTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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);
 }
コード例 #27
0
ファイル: RouterTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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();
 }
コード例 #28
0
ファイル: ControllerTest.php プロジェクト: letsdrink/ouzo
 /**
  * @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');
 }
コード例 #29
0
 /**
  * @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");
 }
コード例 #30
0
ファイル: GeneralAssertTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  * @dataProvider notEqualToNull
  * @param $notNull
  */
 public function shouldNotBeEqual($notNull)
 {
     CatchException::when(GeneralAssert::that(null))->isEqualTo($notNull);
     CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException');
 }