thatString() public static method

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
return Ouzo\Tests\StringAssert
Esempio n. 1
0
 /**
  * @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');
 }
Esempio n. 3
0
 /**
  * @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'));
 }
Esempio n. 4
0
 /**
  * @test
  */
 public function shouldReturnReplacedTemplateContents()
 {
     //given
     $actionGenerator = new ActionGenerator('index');
     //when
     $templateContents = $actionGenerator->templateContents();
     //then
     Assert::thatString($templateContents)->contains('public function index');
 }
Esempio n. 5
0
 /**
  * @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');
 }
Esempio n. 6
0
 /**
  * @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');
 }
Esempio n. 8
0
 /**
  * @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);
 }
Esempio n. 9
0
 /**
  * @test
  */
 public function shouldCheckIsStringIsNotEmpty()
 {
     Assert::thatString('Lady Stoneheart')->isNotEmpty();
 }
Esempio n. 10
0
 public function assertRenderedContent()
 {
     return Assert::thatString($this->getActualContent());
 }
Esempio n. 11
0
 /**
  * @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');
 }
Esempio n. 12
0
 /**
  * @test
  */
 public function shouldGetFirstKeyString()
 {
     //given
     $array = array('foo' => 'bar', 2 => 'example');
     //when
     $first = Arrays::first($array);
     // then
     Assert::thatString($first)->isEqualTo('bar');
 }
Esempio n. 13
0
 /**
  * @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 . ']');
 }
Esempio n. 14
0
    /**
     * @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));
 }