Bravo3\Orm\Tests\RefTest::testDeleteIndicesAndRelationshipsAlt PHP Method

testDeleteIndicesAndRelationshipsAlt() public method

Same as above test, except we'll delete the category
public testDeleteIndicesAndRelationshipsAlt ( EntityManager $em )
$em Bravo3\Orm\Services\EntityManager
    public function testDeleteIndicesAndRelationshipsAlt(EntityManager $em)
    {
        $article1 = new RefArticle();
        $article1->setId(502)->setTitle('Ref Article 502');
        $category1 = new RefCategory();
        $category1->setId(533)->setName('Ref Category 533');
        $article1->setCanonicalCategory($category1);
        $em->persist($category1)->persist($article1)->flush();
        $this->assertTrue($this->exists($em, 'article', '502'));
        $mto = $this->getRelKey($em, 'article', 'category', '502', 'canonical_category', RelationshipType::MANYTOONE());
        $this->assertEquals('533', $em->getDriver()->getSingleValueIndex($mto));
        // Not inversed:
        $otm = $this->getRelKey($em, 'category', 'article', '533', 'articles', RelationshipType::ONETOMANY());
        $this->assertNotContains('502', $em->getDriver()->getMultiValueIndex($otm));
        // Ref exists:
        $refs = $em->getDriver()->getRefs($this->getEntityRefKey($em, 'category', '533'));
        $ref = (string) new Ref(RefArticle::class, '502', 'canonical_category');
        $this->assertCount(1, $refs);
        $this->assertEquals($ref, (string) $refs[0]);
        /** @var RefCategory $category */
        $category = $em->retrieve(RefCategory::class, 533);
        $em->delete($category)->flush();
        $this->assertFalse($this->exists($em, 'category', '533'));
        $this->assertNull($em->getDriver()->getSingleValueIndex($mto));
        $this->assertNotContains('502', $em->getDriver()->getMultiValueIndex($otm));
        // Ref no longer needed:
        $refs = $em->getDriver()->getRefs($this->getEntityRefKey($em, 'category', '533'));
        $this->assertNotContains($ref, $refs);
    }