Skip to content

Commit

Permalink
Refactor deprecated setMethod in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Mar 29, 2021
1 parent 21cc28b commit 0ef00c2
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 68 deletions.
Expand Up @@ -74,7 +74,7 @@ public function testgetWhereFromRequestWithSomeWhere()
];

$request = $this->getMockBuilder(Request::class)
->setMethods(['get'])
->onlyMethods(['get'])
->disableOriginalConstructor()
->getMock();

Expand Down
Expand Up @@ -35,7 +35,7 @@ public function setUp(): void
$this->random = sha1((string) time());
$this->adapter = $this->getMockBuilder(FilesystemTagAwareAdapter::class)
->disableOriginalConstructor()
->setMethods(['clear', 'getCacheAdapter', 'commit'])
->onlyMethods(['clear', 'getCacheAdapter', 'commit'])
->getMock();
$this->adapter->method('clear')->willReturn($this->random);
$this->adapter->method('commit')->willReturn(null);
Expand Down
Expand Up @@ -76,7 +76,7 @@ public function testFetchEmailIdsById(): void

$queryBuilder = $this->getMockBuilder(QueryBuilder::class)
->disableOriginalConstructor()
->setMethods(['select', 'from', 'where', 'setParameter', 'andWhere', 'getQuery'])
->onlyMethods(['select', 'from', 'where', 'setParameter', 'andWhere', 'getQuery'])
->getMock();

$this->entityManager
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testFetchEmailIdsById(): void

$query = $this->getMockBuilder(AbstractQuery::class)
->disableOriginalConstructor()
->setMethods(['setHydrationMode', 'getResult'])
->onlyMethods(['setHydrationMode', 'getResult'])
->getMockForAbstractClass();

$query->expects(self::once())
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/CampaignBundle/Tests/Model/EventModelTest.php
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
{
$this->eventModel = $this->getMockBuilder(EventModel::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'getRepository',
'getLeadEventLogRepository',
'deleteEntities',
Expand Down
Expand Up @@ -308,7 +308,7 @@ public function sendMarketingMessageSms(CampaignExecutionEvent $event)
private function getEvent()
{
$event = $this->getMockBuilder(Event::class)
->setMethods(['getId'])
->onlyMethods(['getId'])
->getMock();
$event->method('getId')
->willReturn(1);
Expand Down Expand Up @@ -375,7 +375,7 @@ private function getLogs()
);

$log = $this->getMockBuilder(LeadEventLog::class)
->setMethods(['getLead', 'getId'])
->onlyMethods(['getLead', 'getId'])
->getMock();
$log->method('getLead')
->willReturn($lead);
Expand All @@ -400,7 +400,7 @@ private function getLogs()
);

$log2 = $this->getMockBuilder(LeadEventLog::class)
->setMethods(['getLead', 'getId'])
->onlyMethods(['getLead', 'getId'])
->getMock();
$log2->method('getLead')
->willReturn($lead2);
Expand Down
Expand Up @@ -171,7 +171,7 @@ public function testOnKernelController()

$request = $this->createMock(Request::class);
$controller = $this->getMockBuilder(MauticController::class)
->setMethods(['initialize', 'setRequest', 'setFactory', 'setUser', 'setCoreParametersHelper', 'setDispatcher', 'setTranslator', 'setFlashBag'])
->onlyMethods(['initialize', 'setRequest', 'setFactory', 'setUser', 'setCoreParametersHelper', 'setDispatcher', 'setTranslator', 'setFlashBag'])
->getMock();
$controllers = [$controller];

Expand Down
Expand Up @@ -40,7 +40,7 @@ class CommonRepositoryTest extends \PHPUnit\Framework\TestCase
protected function setUp(): void
{
$emMock = $this->getMockBuilder(EntityManager::class)
->setMethods(['none'])
->onlyMethods(['none'])
->disableOriginalConstructor()
->getMock();

Expand Down
Expand Up @@ -24,7 +24,7 @@ public function testGetDwcBySlotNameWithPublished(): void
{
$mockModel = $this->getMockBuilder(DynamicContentModel::class)
->disableOriginalConstructor()
->setMethods(['getEntities'])
->onlyMethods(['getEntities'])
->getMock();

$mockModel->expects($this->exactly(2))
Expand Down
Expand Up @@ -101,7 +101,7 @@ public function testDynamicContentCustomTokens()
/** @var TokenSubscriber $subscriber */
$subscriber = $this->getMockBuilder(TokenSubscriber::class)
->setConstructorArgs([$dispatcher, $primaryCompanyHelper])
->setMethods(null)
->onlyMethods(null)
->getMock();

$dispatcher->addSubscriber($subscriber);
Expand Down
4 changes: 2 additions & 2 deletions app/bundles/EmailBundle/Tests/Helper/PointEventHelperTest.php
Expand Up @@ -52,7 +52,7 @@ private function getMockMauticFactory($published = true, $success = true)
{
$mock = $this->getMockBuilder(MauticFactory::class)
->disableOriginalConstructor()
->setMethods(['getModel'])
->onlyMethods(['getModel'])
->getMock()
;

Expand Down Expand Up @@ -95,7 +95,7 @@ private function getMockEmail($published = true, $success = true)

$mock = $this->getMockBuilder(EmailModel::class)
->disableOriginalConstructor()
->setMethods(['getEntity', 'sendEmail'])
->onlyMethods(['getEntity', 'sendEmail'])
->getMock()
;

Expand Down
Expand Up @@ -257,7 +257,7 @@ function ($param) {

$mailHelper = $this->getMockBuilder(MailHelper::class)
->setConstructorArgs([$factoryMock, $mailer])
->setMethods(['createEmailStat'])
->onlyMethods(['createEmailStat'])
->getMock();

$mailHelper->method('createEmailStat')
Expand Down Expand Up @@ -416,7 +416,7 @@ function ($eventName, EmailSendEvent $event) {

$mailHelper = $this->getMockBuilder(MailHelper::class)
->setConstructorArgs([$factoryMock, $mailer])
->setMethods(null)
->onlyMethods(null)
->getMock();

// Enable queueing
Expand Down Expand Up @@ -519,7 +519,7 @@ function ($param) {

$mailHelper = $this->getMockBuilder(MailHelper::class)
->setConstructorArgs([$factoryMock, $mailer])
->setMethods(['createEmailStat'])
->onlyMethods(['createEmailStat'])
->getMock();

$mailHelper->expects($this->exactly(21))
Expand Down Expand Up @@ -656,7 +656,7 @@ function ($param) {

$mailHelper = $this->getMockBuilder(MailHelper::class)
->setConstructorArgs([$factoryMock, $mailer])
->setMethods(['createEmailStat'])
->onlyMethods(['createEmailStat'])
->getMock();

$mailHelper->method('createEmailStat')
Expand Down
Expand Up @@ -46,7 +46,7 @@ public function testOnReportBuilderAddsFormAndFormSubmissionReports()
{
$mockEvent = $this->getMockBuilder(ReportBuilderEvent::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'checkContext',
'addGraph',
'getStandardColumns',
Expand Down Expand Up @@ -117,7 +117,7 @@ public function testOnReportGenerateFormsContext()
$mockQueryBuilder = $this->createMock(QueryBuilder::class);
$mockEvent = $this->getMockBuilder(ReportGeneratorEvent::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'getContext',
'getQueryBuilder',
'addCategoryLeftJoin',
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testOnReportGenerateFormSubmissionContext()
$mockQueryBuilder = $this->createMock(QueryBuilder::class);
$mockEvent = $this->getMockBuilder(ReportGeneratorEvent::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'getContext',
'getQueryBuilder',
'addCategoryLeftJoin',
Expand Down
Expand Up @@ -63,7 +63,7 @@ protected function setUp(): void
// This is terrible, but the Query class is final and AbstractQuery doesn't have some methods used.
$this->query = $this->getMockBuilder(AbstractQuery::class)
->disableOriginalConstructor()
->setMethods(['setParameters', 'setFirstResult', 'setMaxResults', 'getSingleResult', 'getSQL', '_doExecute'])
->onlyMethods(['setParameters', 'setFirstResult', 'setMaxResults', 'getSingleResult', 'getSQL', '_doExecute'])
->getMock();

$this->entityManager->expects($this->once())
Expand Down
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void
{
$this->syncDateHelper = $this->getMockBuilder(SyncDateHelper::class)
->disableOriginalConstructor()
->setMethods(['getLastSyncDateForObject'])
->onlyMethods(['getLastSyncDateForObject'])
->getMock();
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ public function testgetWhereFromRequestWithSomeWhere()
];

$request = $this->getMockBuilder(Request::class)
->setMethods(['get'])
->onlyMethods(['get'])
->disableOriginalConstructor()
->getMock();

Expand Down
6 changes: 3 additions & 3 deletions app/bundles/LeadBundle/Tests/Entity/LeadRepositoryTest.php
Expand Up @@ -86,7 +86,7 @@ public function testBuildQueryForGetLeadsByFieldValue()

$mock = $this->getMockBuilder(LeadRepository::class)
->disableOriginalConstructor()
->setMethods(['getEntityManager'])
->onlyMethods(['getEntityManager'])
->getMock();

$mock->method('getEntityManager')
Expand All @@ -110,13 +110,13 @@ public function testGetLeadsByFieldValueArrayMapReturn()
{
$mock = $this->getMockBuilder(LeadRepository::class)
->disableOriginalConstructor()
->setMethods(['getEntities', 'buildQueryForGetLeadsByFieldValue'])
->onlyMethods(['getEntities', 'buildQueryForGetLeadsByFieldValue'])
->getMock();

// Mock the
$mockEntity = $this->getMockBuilder(Lead::class)
->disableOriginalConstructor()
->setMethods(['loadMetadata'])
->onlyMethods(['loadMetadata'])
->getMock();

$mockEntity->setEmail('test@example.com');
Expand Down
4 changes: 2 additions & 2 deletions app/bundles/LeadBundle/Tests/Entity/TagRepositoryTest.php
Expand Up @@ -24,7 +24,7 @@ public function testGetTagByNameOrCreateNewOneWithSomeExistingTag()

$mockRepository = $this->getMockBuilder(TagRepository::class)
->disableOriginalConstructor()
->setMethods(['findOneBy'])
->onlyMethods(['findOneBy'])
->getMock();

$mockRepository->expects($this->once())
Expand All @@ -39,7 +39,7 @@ public function testGetTagByNameOrCreateNewOneWithSomeNewTag()
{
$mockRepository = $this->getMockBuilder(TagRepository::class)
->disableOriginalConstructor()
->setMethods(['findOneBy'])
->onlyMethods(['findOneBy'])
->getMock();

$mockRepository->expects($this->once())
Expand Down
Expand Up @@ -891,7 +891,7 @@ public function testonReportGraphGenerate($event)

$mockStmt = $this->getMockBuilder(PDOStatement::class)
->disableOriginalConstructor()
->setMethods(['fetchAll'])
->onlyMethods(['fetchAll'])
->getMock();

$this->reportGraphEventMock->expects($this->once())
Expand All @@ -900,7 +900,7 @@ public function testonReportGraphGenerate($event)

$mockChartQuery = $this->getMockBuilder(ChartQuery::class)
->disableOriginalConstructor()
->setMethods([
->onlyMethods([
'modifyCountQuery',
'modifyTimeDataQuery',
'loadAndBuildTimeData',
Expand Down
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void

$this->fieldRepository = $this->createMock(LeadFieldRepository::class);
$this->fieldModel = $this->getMockBuilder(FieldModel::class)
->setMethods(['cleanAlias', 'getRepository'])
->onlyMethods(['cleanAlias', 'getRepository'])
->disableOriginalConstructor()
->getMock();

Expand Down
2 changes: 1 addition & 1 deletion app/bundles/LeadBundle/Tests/Model/CompanyModelTest.php
Expand Up @@ -26,7 +26,7 @@ public function testArrayValueIsFlattenedBeforeSave()
/** @var CompanyModel $companyModel */
$companyModel = $this->getMockBuilder(CompanyModel::class)
->disableOriginalConstructor()
->setMethods(null)
->onlyMethods(null)
->getMock();

$company = new Company();
Expand Down
16 changes: 8 additions & 8 deletions app/bundles/LeadBundle/Tests/Model/ImportModelTest.php
Expand Up @@ -62,7 +62,7 @@ public function testCheckParallelImportLimitWhenMore()
{
$entity = $this->initImportEntity();
$model = $this->getMockBuilder(ImportModel::class)
->setMethods(['getParallelImportLimit', 'getRepository'])
->onlyMethods(['getParallelImportLimit', 'getRepository'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -71,7 +71,7 @@ public function testCheckParallelImportLimitWhenMore()
->will($this->returnValue(4));

$repository = $this->getMockBuilder(ImportRepository::class)
->setMethods(['countImportsWithStatuses'])
->onlyMethods(['countImportsWithStatuses'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -92,7 +92,7 @@ public function testCheckParallelImportLimitWhenEqual()
{
$entity = $this->initImportEntity();
$model = $this->getMockBuilder(ImportModel::class)
->setMethods(['getParallelImportLimit', 'getRepository'])
->onlyMethods(['getParallelImportLimit', 'getRepository'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -101,7 +101,7 @@ public function testCheckParallelImportLimitWhenEqual()
->will($this->returnValue(4));

$repository = $this->getMockBuilder(ImportRepository::class)
->setMethods(['countImportsWithStatuses'])
->onlyMethods(['countImportsWithStatuses'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -122,7 +122,7 @@ public function testCheckParallelImportLimitWhenLess()
{
$entity = $this->initImportEntity();
$model = $this->getMockBuilder(ImportModel::class)
->setMethods(['getParallelImportLimit', 'getRepository'])
->onlyMethods(['getParallelImportLimit', 'getRepository'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -131,7 +131,7 @@ public function testCheckParallelImportLimitWhenLess()
->will($this->returnValue(6));

$repository = $this->getMockBuilder(ImportRepository::class)
->setMethods(['countImportsWithStatuses'])
->onlyMethods(['countImportsWithStatuses'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -151,7 +151,7 @@ public function testCheckParallelImportLimitWhenLess()
public function testBeginImportWhenParallelLimitHit()
{
$model = $this->getMockBuilder(ImportModel::class)
->setMethods(['checkParallelImportLimit', 'setGhostImportsAsFailed', 'saveEntity', 'getParallelImportLimit'])
->onlyMethods(['checkParallelImportLimit', 'setGhostImportsAsFailed', 'saveEntity', 'getParallelImportLimit'])
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -187,7 +187,7 @@ public function testBeginImportWhenParallelLimitHit()
public function testBeginImportWhenDatabaseException()
{
$model = $this->getMockBuilder(ImportModel::class)
->setMethods(['checkParallelImportLimit', 'setGhostImportsAsFailed', 'saveEntity', 'logDebug', 'process'])
->onlyMethods(['checkParallelImportLimit', 'setGhostImportsAsFailed', 'saveEntity', 'logDebug', 'process'])
->disableOriginalConstructor()
->getMock();

Expand Down
4 changes: 2 additions & 2 deletions app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php
Expand Up @@ -14,15 +14,15 @@ protected function setUp(): void
{
$mockListModel = $this->getMockBuilder(ListModel::class)
->disableOriginalConstructor()
->setMethods(['getEntities', 'getEntity'])
->onlyMethods(['getEntities', 'getEntity'])
->getMock();

$mockListModel->expects($this->any())
->method('getEntity')
->willReturnCallback(function ($id) {
$mockEntity = $this->getMockBuilder(LeadList::class)
->disableOriginalConstructor()
->setMethods(['getName'])
->onlyMethods(['getName'])
->getMock();

$mockEntity->expects($this->once())
Expand Down

0 comments on commit 0ef00c2

Please sign in to comment.