вызов неопределенного метода Prophecy \ Prophecy \ MethodProphecy :: connect () доктрина - PullRequest
0 голосов
/ 21 октября 2019
class connectionDatabase
{
    public function checkConnectionFocco(string $message = "Erro ao conectar 
    banco de dados Focco!"): bool
        {
            try {
                $this->entityManager->getConnection();
        } catch (Exception $e) {
            throw new FoccoDatabaseConnectionException($message, 500);
        }
    }
}

public function checkConnectionFocco(string $message = "Erro ao conectar 
    banco de dados Focco!"): bool
        {
            try {
                $this->entityManager->getConnection();
            } catch (Exception $e) {
                throw new FoccoDatabaseConnectionException($message, 500);
        }
    }
}


class FoccoDatabaseConnectionExceptionTest extends TestCase
{
    /**
     * @var EntityManager
     */
    private $entityManager;

    /**
     * @var CheckFoccoDatabaseConnection
     */
    private $connectionFocco;

    public function setUp()
    {
        $this->entityManager = $this->prophesize(EntityManager::class);
        $this->connectionFocco = new CheckFoccoDatabaseConnection($this->entityManager->reveal());
    }

    public function testVerificaSeConexaoEstaEstabelecida()
    {
        $this->entityManager->getConnection()->willReturn(Connection::class)->shouldBeCalled();
        $this->entityManager->getConnection()->connect()->shouldReturn(true)->shouldBeCalled();

        $conectado = $this->connectionFocco->checkConnectionFocco();

        $this->assertEquals(true, $conectado);

    }
}
...