Example #1
0
    /**
     * @covers Zend\Db\Sql\Update::where
     */
    public function testWhere()
    {
        $this->update->where('x = y');
        $this->update->where(array('foo > ?' => 5));
        $this->update->where(array('id' => 2));
        $this->update->where(array('a = b'), Where::OP_OR);
        $where = $this->update->where;

        $predicates = $this->readAttribute($where, 'predicates');
        $this->assertEquals('AND', $predicates[0][0]);
        $this->assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[0][1]);

        $this->assertEquals('AND', $predicates[1][0]);
        $this->assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[1][1]);

        $this->assertEquals('AND', $predicates[2][0]);
        $this->assertInstanceOf('Zend\Db\Sql\Predicate\Operator', $predicates[2][1]);

        $this->assertEquals('OR', $predicates[3][0]);
        $this->assertInstanceOf('Zend\Db\Sql\Predicate\Expression', $predicates[3][1]);

        $where = new Where;
        $this->update->where($where);
        $this->assertSame($where, $this->update->where);

        $test = $this;
        $this->update->where(function ($what) use ($test, $where) {
            $test->assertSame($where, $what);
        });
    }
 public function testChecarSeOSqlRetornaCorretoComWhere()
 {
     $update = new Update();
     $where = new Where();
     $where->set('id', '=', 1);
     $update->where($where);
     $fields = ['name' => 'Erik'];
     $update->fields($fields);
     $sql = $update->sql();
     $this->assertEquals('UPDATE `users` SET `name`=:name WHERE `id`=:id;', $sql);
 }