Phalcon\Test\Mvc\Model\Behavior\Helper::checkIntegrity PHP Method

checkIntegrity() protected method

Checking the integrity of keys
protected checkIntegrity ( integer | null $rootId = null )
$rootId integer | null
    protected function checkIntegrity($rootId = null)
    {
        $connection = $this->getConnection();
        $sql = "SELECT COUNT(*) cnt FROM categories WHERE lft >= rgt";
        if ($rootId) {
            $sql .= " AND root = {$rootId}";
        }
        /** @var \Phalcon\Db\Result\Pdo $check1 */
        $check1 = $connection->query($sql);
        $this->assertEquals(['cnt' => '0'], $check1->fetch(\PDO::FETCH_ASSOC));
        $sql = "SELECT COUNT(*) cnt, MIN(lft) min, MAX(rgt) max FROM categories";
        if ($rootId) {
            $sql .= " WHERE root = {$rootId}";
        }
        /** @var \Phalcon\Db\Result\Pdo $check2 */
        $check2 = $connection->query($sql);
        $result = $check2->fetch(\PDO::FETCH_ASSOC);
        $this->assertEquals(1, $result['min']);
        $this->assertEquals($result['cnt'] * 2, $result['max']);
        $sql = "SELECT COUNT(*) cnt FROM categories WHERE MOD((rgt - lft), 2) = 0";
        if ($rootId) {
            $sql .= " AND root = {$rootId}";
        }
        /** @var \Phalcon\Db\Result\Pdo $check3 */
        $check3 = $connection->query($sql);
        $this->assertEquals(['cnt' => '0'], $check3->fetch(\PDO::FETCH_ASSOC));
        $sql = "SELECT COUNT(*) cnt FROM categories WHERE MOD((lft - level + 2), 2) = 1";
        if ($rootId) {
            $sql .= " AND root = {$rootId}";
        }
        /** @var \Phalcon\Db\Result\Pdo $check4 */
        $check4 = $connection->query($sql);
        $this->assertEquals(['cnt' => '0'], $check4->fetch(\PDO::FETCH_ASSOC));
    }