/**
  * @test
  */
 public function shouldHandleRightExclusiveMode()
 {
     //given
     $restriction = Restrictions::between(1, 3, Between::RIGHT_EXCLUSIVE);
     //when
     $sql = $restriction->toSql('key');
     //then
     $this->assertEquals('(key >= ? AND key < ?)', $sql);
 }
 /**
  * @test
  */
 public function shouldCreateSql()
 {
     //given
     $restriction = Restrictions::isNotNull();
     //when
     $sql = $restriction->toSql('category_id');
     //then
     $this->assertEquals('category_id IS NOT NULL', $sql);
 }
 /**
  * @test
  */
 public function shouldReturnNullForEmptyArray()
 {
     //given
     $restriction = Restrictions::isNotIn(array());
     //when
     $sql = $restriction->toSql('category_id');
     //then
     $this->assertNull($sql);
 }
 /**
  * @test
  */
 public function shouldCreateProperSql()
 {
     //given
     $restriction = Restrictions::greaterOrEqualTo(5);
     //when
     $sql = $restriction->toSql('key');
     //then
     $this->assertEquals('key >= ?', $sql);
     $this->assertEquals(array(5), $restriction->getValues());
 }
Example #5
0
 /**
  * @test
  */
 public function shouldCreateProperSql()
 {
     //given
     $restriction = Restrictions::like('value');
     //when
     $sql = $restriction->toSql('key');
     //then
     $this->assertEquals('key LIKE ?', $sql);
     $this->assertEquals(array('value'), $restriction->getValues());
 }
 /**
  * @test
  */
 public function shouldCreateProperSqlForEmptyString()
 {
     //given
     $restriction = Restrictions::notEqualTo('');
     //when
     $sql = $restriction->toSql('key');
     //then
     $this->assertEquals('key <> ?', $sql);
     $this->assertEquals(array(''), $restriction->getValues());
 }
Example #7
0
 /**
  * @test
  */
 public function shouldCreateProperSqlForSqlite()
 {
     //given
     Config::overrideProperty('sql_dialect')->with('\\Ouzo\\Db\\Dialect\\Sqlite3Dialect');
     $restriction = Restrictions::regexp('value');
     //when
     $sql = $restriction->toSql('key');
     //then
     $this->assertEquals('key REGEXP ?', $sql);
     $this->assertEquals(array('value'), $restriction->getValues());
 }
Example #8
0
 public function __construct($where, $operator = 'AND')
 {
     foreach ($where as $column => $value) {
         if ($value === null) {
             $where[$column] = Restrictions::isNull();
         }
     }
     $this->where = $where;
     $this->values = Arrays::flatten(array_values($where));
     $this->operator = $operator;
 }
Example #9
0
 /**
  * @return Event[]
  */
 public static function loadNew()
 {
     $lastEventId = Session::get('last_event_id');
     if (!$lastEventId) {
         //do not load events that we triggered before this session was started
         /** @var Event $lastEvent */
         $lastEvent = Event::queryBuilder()->limit(1)->order('id desc')->fetch();
         Session::set('last_event_id', $lastEvent ? $lastEvent->id : 0);
     }
     $events = Event::where(['id' => Restrictions::greaterThan($lastEventId)])->order('id asc')->fetchAll();
     if ($events) {
         Session::set('last_event_id', Arrays::last($events)->id);
     }
     return $events;
 }
Example #10
0
 /**
  * @test
  */
 public function shouldSearchAnyOfAndWhereValues()
 {
     //given
     $category = Category::create(array('name' => 'shop'));
     $product1 = Product::create(array('name' => 'notebook', 'description' => 'notebook desc', 'id_category' => $category->getId()));
     $product2 = Product::create(array('name' => 'tablet', 'description' => 'tablet desc', 'id_category' => $category->getId()));
     Product::create(array('name' => 'pc', 'description' => 'pc desc'));
     //when
     $products = Product::where(Any::of(array('name' => 'tablet', 'description' => Restrictions::like('%desc'))))->where(array('id_category' => $category->getId()))->fetchAll();
     //then
     Assert::thatArray($products)->hasSize(2)->onProperty('id')->containsExactly($product1->getId(), $product2->getId());
 }
Example #11
0
 /**
  * @group non-sqlite3
  * @test
  */
 public function shouldReturnModelUsingRegexpRestriction()
 {
     //given
     $product = Product::create(array('name' => 'name1', 'description' => 'desc'));
     Product::create(array('name' => 'other product', 'description' => 'desc'));
     //when
     $loadedProduct = Product::where(array('name' => Restrictions::regexp('ame')))->fetch();
     //then
     Assert::thatModel($loadedProduct)->isEqualTo($product);
 }
Example #12
0
 /**
  * @test
  */
 public function shouldNotAddParenthesisToSingleOfRestriction()
 {
     // when
     $result = WhereClause::create(array('a' => Restrictions::equalTo('b')));
     // then
     $this->assertInstanceOf('\\Ouzo\\Db\\WhereClause\\ArrayWhereClause', $result);
     $this->assertEquals('a = ?', $result->toSql());
 }