tests/Entity/SnapshotManagerTest.php
/**
     * Tests the enableSnapshots() method to ensure execute queries are correct.
     */
Tests the enableSnapshots() method to ensure execute queries are correct.
Tests the enableSnapshots () method to ensure execute queries are correct .
public function testEnableSnapshots(): void
    {
        $page = $this->createMock(PageInterface::class);
        $page->expects(static::once())->method('getId')->willReturn(456);
        $snapshot = $this->createMock(Snapshot::class);
        $snapshot->expects(static::once())->method('getId')->willReturn(123);
        $snapshot->expects(static::once())->method('getPage')->willReturn($page);
        $date = new \DateTime();
        $connection = $this->createMock(Connection::class);
        $connection
            ->expects(static::once())
            ->method('query')
            ->with(sprintf(
                "UPDATE page_snapshot SET publication_date_end = '%s' WHERE id NOT IN(123) AND page_id IN (456) and publication_date_end IS NULL",
                $date->format('Y-m-d H:i:s')
            ));
        $em = $this->createMock(EntityManagerInterface::class);
        $em->expects(static::once())->method('persist')->with($snapshot);
        $em->expects(static::once())->method('flush');
        $em->expects(static::once())->method('getConnection')->willReturn($connection);
        $manager = $this->getMockBuilder(SnapshotManager::class)
            ->disableOriginalConstructor()
            ->setMethods(['getEntityManager', 'getTableName'])
            ->getMock();
        $manager->expects(static::exactly(3))->method('getEntityManager')->willReturn($em);
        $manager->expects(static::once())->method('getTableName')->willReturn('page_snapshot');
        $manager->enableSnapshots([$snapshot], $date);
    }
public function testEnableSnapshots ( ) : void { $ page = $ this -> createMock ( PageInterface :: class ) ; $ page -> expects ( static :: once ( ) ) -> method ( 'getId' ) -> willReturn ( 456 ) ; $ snapshot = $ this -> createMock ( Snapshot :: class ) ; $ snapshot -> expects ( static :: once ( ) ) -> method ( 'getId' ) -> willReturn ( 123 ) ; $ snapshot -> expects ( static :: once ( ) ) -> method ( 'getPage' ) -> willReturn ( $ page ) ; $ date = new \ DateTime ( ) ; $ connection = $ this -> createMock ( Connection :: class ) ; $ connection -> expects ( static :: once ( ) ) -> method ( 'query' ) -> with ( sprintf ( " UPDATE page_snapshot SET publication_date_end = '%s' WHERE id NOT IN(123) AND page_id IN (456) and publication_date_end IS NULL " , $ date -> format ( 'Y-m-d H:i:s' ) ) ) ; $ em = $ this -> createMock ( EntityManagerInterface :: class ) ; $ em -> expects ( static :: once ( ) ) -> method ( 'persist' ) -> with ( $ snapshot ) ; $ em -> expects ( static :: once ( ) ) -> method ( 'flush' ) ; $ em -> expects ( static :: once ( ) ) -> method ( 'getConnection' ) -> willReturn ( $ connection ) ; $ manager = $ this -> getMockBuilder ( SnapshotManager :: class ) -> disableOriginalConstructor ( ) -> setMethods ( [ 'getEntityManager' , 'getTableName' ] ) -> getMock ( ) ; $ manager -> expects ( static :: exactly ( 3 ) ) -> method ( 'getEntityManager' ) -> willReturn ( $ em ) ; $ manager -> expects ( static :: once ( ) ) -> method ( 'getTableName' ) -> willReturn ( 'page_snapshot' ) ; $ manager -> enableSnapshots ( [ $ snapshot ] , $ date ) ; }
Tests the enableSnapshots() method to ensure execute queries are correct.
Tests the enableSnapshots () method to ensure execute queries are correct .
// Given // When calling method, expects calls