RedUNIT\Base\Association::testSingleColUniqueConstraint PHP Method

testSingleColUniqueConstraint() public method

Test single column bases unique constraints.
    public function testSingleColUniqueConstraint()
    {
        testpack('Testing unique constraint on single column');
        $book = R::dispense('book');
        $book->title = 'bla';
        $book->extra = 2;
        $id = R::store($book);
        R::getWriter()->addUniqueIndex('book', array('title'));
        $book = R::dispense('book');
        $book->title = 'bla';
        $expected = NULL;
        try {
            R::store($book);
            fail();
        } catch (SQL $e) {
            $expected = $e;
        }
        asrt($expected instanceof SQL, TRUE);
        asrt(R::count('book'), 1);
        $book = R::load('book', $id);
        // Causes failure, table will be rebuild
        $book->extra = 'CHANGE';
        $id2 = R::store($book);
        $book2 = R::load('book', $id2);
        $book = R::dispense('book');
        $book->title = 'bla';
        try {
            R::store($book);
            fail();
        } catch (SQL $e) {
            $expected = $e;
        }
        asrt($expected instanceof SQL, TRUE);
        asrt(R::count('book'), 1);
    }