21 private $connectionFactoryMock;
26 private $queryFactoryMock;
36 private $connectionMock;
46 private $objectManagerHelper;
51 private $reportValidator;
58 $this->connectionFactoryMock = $this->getMockBuilder(ConnectionFactory::class)
59 ->disableOriginalConstructor()->getMock();
60 $this->queryFactoryMock = $this->getMockBuilder(QueryFactory::class)
61 ->disableOriginalConstructor()->getMock();
62 $this->queryMock = $this->getMockBuilder(Query::class)->disableOriginalConstructor()
64 $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass();
65 $this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor()
67 $this->objectManagerHelper =
new ObjectManagerHelper($this);
69 $this->reportValidator = $this->objectManagerHelper->getObject(
70 ReportValidator::class,
72 'connectionFactory' => $this->connectionFactoryMock,
73 'queryFactory' => $this->queryFactoryMock
84 public function testValidate($reportName,
$result, \PHPUnit\Framework\MockObject\Stub $queryReturnStub)
86 $connectionName =
'testConnection';
87 $this->queryFactoryMock->expects($this->once())
89 ->willReturn($this->queryMock);
90 $this->queryMock->expects($this->once())->method(
'getConnectionName')->willReturn($connectionName);
91 $this->connectionFactoryMock->expects($this->once())->method(
'getConnection')
92 ->with($connectionName)
93 ->willReturn($this->connectionMock);
94 $this->queryMock->expects($this->atLeastOnce())->method(
'getSelect')->willReturn($this->selectMock);
95 $this->selectMock->expects($this->once())->method(
'limit')->with(0);
96 $this->connectionMock->expects($this->once())->method(
'query')->with($this->selectMock)->will($queryReturnStub);
97 $this->assertEquals(
$result, $this->reportValidator->validate($reportName));
107 $reportName =
'test';
108 $errorMessage =
'SQL Error 42';
112 'expectedResult' => [],
113 'queryReturnStub' => $this->returnValue(
null)
117 'expectedResult' => [$reportName, $errorMessage],
testValidate($reportName, $result, \PHPUnit\Framework\MockObject\Stub $queryReturnStub)