Sample usage:
Assert::thatString("Frodo")->startsWith("Fro")->endsWith("do")->contains("rod")->doesNotContain("fro")->hasSize(5)->matches('/Fro\w+/');
public static thatString ( string $string ) : Ouzo\Tests\StringAssert | ||
$string | string | |
Результат | Ouzo\Tests\StringAssert |
/** * @test */ public function shouldBuildNotExistsClause() { // when $result = WhereClause::notExists(Product::where(array('name' => 'phone'))); // then $this->assertEquals(array('phone'), $result->getParameters()); Assert::thatString($result->toSql())->startsWith('NOT EXISTS (SELECT')->endsWith('FROM products WHERE name = ?)'); }
/** * @test */ public function shouldReplaceClassNameAndNamespace() { //given $generator = new ControllerGenerator('users'); //when $templateContents = $generator->templateContents(); //then Assert::thatString($templateContents)->contains('namespace \\Application\\Controller;')->contains('class UsersController extends Controller'); }
/** * @test */ public function shouldResolveDirectoryPath() { //given $resolver = ClassPathResolver::forClassAndNamespace('UserAcl', '\\Application\\View'); //when $directoryPath = $resolver->getClassDirectory(); //then Assert::thatString($directoryPath)->endsWith(Path::join('Application', 'View', 'UserAcl')); }
/** * @test */ public function shouldReturnReplacedTemplateContents() { //given $actionGenerator = new ActionGenerator('index'); //when $templateContents = $actionGenerator->templateContents(); //then Assert::thatString($templateContents)->contains('public function index'); }
/** * @test */ public function shouldNotReplaceWhenTableNameIsPartOfOtherTableName() { //given $onClauses = array(WhereClause::create('products.active = true'), WhereClause::create('order_products.active = true')); $joinClause = new JoinClause('products', 'id', 'product_id', 'order_products', 'p', 'LEFT', $onClauses); //when $buildJoinQueryPart = DialectUtil::buildJoinQueryPart($joinClause); //then Assert::thatString($buildJoinQueryPart)->isEqualTo('LEFT JOIN products AS p ON p.id = order_products.product_id AND p.active = true AND order_products.active = true'); }
/** * @test */ public function shouldGenerateClassWithShortArrays() { //given $classStub = new ClassStub(true); //when $classStub->addColumn(new DatabaseColumn('field1', 'string'))->addColumn(new DatabaseColumn('field2', 'string')); //then Assert::thatString($classStub->contents())->contains("['field1', 'field2']")->contains('$attributes = []')->contains('parent::__construct([ {table_table}'); }
/** * @test */ public function shouldAddEmptyPrimaryKeyEntryWhenNoFoundPrimaryKeyInTable() { //given /** @var Dialect $dialect */ $dialect = Mock::mock('Ouzo\\Tools\\Model\\Template\\Dialect\\Dialect'); Mock::when($dialect)->primaryKey()->thenReturn(''); Mock::when($dialect)->columns()->thenReturn(array()); $classStubReplacer = new ClassStubPlaceholderReplacer('Customer', new TableInfo($dialect)); //when $classContents = $classStubReplacer->contents(); //then Assert::thatString($classContents)->isNotEqualTo('')->contains('primaryKey'); }
/** * @test */ public function shouldIgnoreDebugMessageIfDebugIsOff() { //given Config::overrideProperty('debug')->with(false); //when $this->logger->debug('My debug log line without params.'); //then $logContent = $this->_readStreamContent('test://stdout'); Assert::thatString($logContent)->hasSize(0); }
/** * @test */ public function shouldCheckIsStringIsNotEmpty() { Assert::thatString('Lady Stoneheart')->isNotEmpty(); }
public function assertRenderedContent() { return Assert::thatString($this->getActualContent()); }
/** * @test */ public function shouldExtractArrayValue() { //given $object = array('key' => 'value'); //$function = Functions::extract()['key']; only i php 5.4 $function = Functions::extract()->offsetGet('key'); //when $result = Functions::call($function, $object); //then Assert::thatString($result)->isEqualTo('value'); }
/** * @test */ public function shouldGetFirstKeyString() { //given $array = array('foo' => 'bar', 2 => 'example'); //when $first = Arrays::first($array); // then Assert::thatString($first)->isEqualTo('bar'); }
/** * @test */ public function shouldReturnDerivedClassNameInInspect() { //given $product = Product::create(array('name' => 'Sport')); //when $string = $product->inspect(); //then Assert::thatString($string)->isEqualTo('Application\\Model\\Test\\Product[<name> => "Sport", <id> => ' . $product->id . ']'); }
/** * @test */ public function shouldAppendActionWhenControllerHasActions() { //given $controllerStub = '<?php namespace \\Application\\Controller; use Ouzo\\Controller; class UsersController extends Controller { public function index() { echo "some actions"; $this->view->render(); } }'; file_put_contents($this->controllerPath, $controllerStub); $controllerGenerator = new ControllerGenerator('users', $this->controllerPath); //when $appendAction = $controllerGenerator->appendAction(new ActionGenerator('save')); //then $this->assertTrue($appendAction); Assert::thatString($controllerGenerator->getControllerContents())->contains('public function index()')->contains('echo "some actions";')->contains('public function save()'); }
/** * @test */ public function shouldQuoteParams() { //given $sql = "select * from users where surname = ?"; $param = "' or '1' = '1"; //when $result = PreparedStatementEmulator::substitute($sql, array($param)); //then Assert::thatString($result)->isEqualTo("select * from users where surname = " . Db::getInstance()->_dbHandle->quote($param)); }