when() 공개 정적인 메소드

public static when ( $object )
예제 #1
0
 /**
  * @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');
 }
예제 #2
0
 /**
  * @test
  */
 public function shouldCheckIsCodeEquals()
 {
     //given
     $object = new MyClass();
     //when
     CatchException::when($object)->someMethodThatThrowsException();
     //then
     CatchException::assertThat()->hasCode(555);
 }
예제 #3
0
 /**
  * @test
  */
 public function getShouldThrowExceptionOnNull()
 {
     //given
     $optional = Optional::fromNullable(null);
     //when
     CatchException::when($optional)->get();
     //then
     CatchException::assertThat()->isInstanceOf('\\Exception');
 }
예제 #4
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');
 }
예제 #5
0
 /**
  * @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');
 }
예제 #6
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');
 }
 /**
  * @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');
 }
예제 #8
0
 /**
  * @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');
 }
예제 #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
 /**
  * @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');
 }
예제 #11
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();
 }
예제 #12
0
 /**
  * @test
  */
 public function shouldFailIfStringsAreEqualWhenTheyShouldNotBe()
 {
     CatchException::when(Assert::thatString("Frodo"))->isNotEqualTo('Frodo');
     CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException');
 }
예제 #13
0
 /**
  * @test
  */
 public function shouldThrowExceptionWhenVarNotDefinedForInject()
 {
     //when
     CatchException::when($this->injector)->getInstance('\\ClassWithInvalidDep');
     //then
     CatchException::assertThat()->isInstanceOf('\\Ouzo\\Injection\\InjectorException');
 }
예제 #14
0
 /**
  * @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');
 }
예제 #15
0
 /**
  * @test
  */
 public function shouldNotValidateGetMethod()
 {
     //when
     CatchException::when($this)->get('/csrf_sample/index');
     //then
     CatchException::assertThat()->notCaught();
 }
예제 #16
0
 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');
 }
예제 #18
0
 /**
  * @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();
 }
예제 #19
0
 /**
  * @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');
 }
예제 #20
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');
 }
예제 #21
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");
 }
예제 #22
0
 /**
  * @test
  * @dataProvider notEqualToNull
  * @param $notNull
  */
 public function shouldNotBeEqual($notNull)
 {
     CatchException::when(GeneralAssert::that(null))->isEqualTo($notNull);
     CatchException::assertThat()->isInstanceOf('PHPUnit_Framework_ExpectationFailedException');
 }
예제 #23
0
 /**
  * @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);
 }
예제 #24
0
 /**
  * @test
  */
 public function shouldThrowExceptionIfFirstCalledForEmptyIterator()
 {
     //given
     $iterator = FluentIterator::fromArray(array());
     // when
     CatchException::when($iterator)->first();
     // then
     CatchException::assertThat()->isInstanceOf('\\InvalidArgumentException');
 }
예제 #25
0
 /**
  * @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');
 }
예제 #26
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();
 }
예제 #27
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);
 }
예제 #28
0
 /**
  * @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');
 }
예제 #29
0
 /**
  * @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<');
 }
예제 #30
0
 /**
  * @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);
 }