Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typo3 v8 #5

Merged
merged 9 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 54 additions & 44 deletions Tests/Functional/System/Typo3/TCATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public function setUp()
{
parent::setUp();

$this->tca = $this->getMock(
'Tx_FeatureFlag_System_Typo3_TCA',
[
$this->tca = $this
->getMockBuilder('Tx_FeatureFlag_System_Typo3_TCA')
->setMethods([
'getMappingRepository', 'getFeatureFlagRepository',
aoekrz marked this conversation as resolved.
Show resolved Hide resolved
'getFeatureFlagByUid', 'getPersistenceManager', 'getLanguageService'
]
);
])
->getMock();
$persistenceManager = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)
->disableOriginalConstructor()
->setMethods(['persistAll'])
Expand Down Expand Up @@ -81,16 +81,19 @@ protected function tearDown()
*/
public function selectRendersCorrectly()
{
$featureFlag = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid']);
$featureFlag = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_FeatureFlag')->setMethods(['getUid'])->getMock();
$featureFlag->expects($this->any())->method('getUid')->willReturn(4711);
$mapping = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping', ['getFeatureFlag']);
$mapping = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_Mapping')->setMethods(['getFeatureFlag'])->getMock();
$mapping->expects($this->any())->method('getFeatureFlag')->willReturn($featureFlag);
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid']
);
$mappingRepository = $this
->getMockBuilder('Tx_FeatureFlag_Domain_Repository_Mapping')
->setMethods(['findOneByForeignTableNameAndUid'])
->getMock();
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn($mapping);
$featureFlagRepository = $this->getMock('Tx_FeatureFlag_Domain_Repository_FeatureFlag', ['findAll']);
$featureFlagRepository = $this
->getMockBuilder('Tx_FeatureFlag_Domain_Repository_FeatureFlag')
->setMethods(['findAll'])
->getMock();
$featureFlagRepository->expects($this->once())->method('findAll')->willReturn($this->getListOfFeatureFlags());
$this->tca->expects($this->once())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->once())->method('getFeatureFlagRepository')->willReturn($featureFlagRepository);
Expand All @@ -115,18 +118,17 @@ public function selectRendersCorrectly()
*/
public function processDatamapDoNothingIfNothingSelected()
{
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'add', 'remove', 'update']
);
$mappingRepository = $this->getMockBuilder('Tx_FeatureFlag_Domain_Repository_Mapping')
->setMethods(['findOneByForeignTableNameAndUid', 'add', 'remove', 'update'])
->getMock();
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn(null);
$mappingRepository->expects($this->never())->method('add');
$mappingRepository->expects($this->never())->method('remove');
$mappingRepository->expects($this->never())->method('update');
$this->tca->expects($this->once())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->never())->method('getFeatureFlagByUid');

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->getMockBuilder(\TYPO3\CMS\Core\DataHandling\DataHandler::class)->getMock();
$incomingFieldArray = [
'tx_featureflag_flag' => '0',
'tx_featureflag_behavior' => '0',
Expand All @@ -139,18 +141,18 @@ public function processDatamapDoNothingIfNothingSelected()
*/
public function processDatamapDoNothingIfNotInFeatureFlagContext()
{
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'add', 'remove', 'update']
);
$mappingRepository = $this->getMockBuilder(
'Tx_FeatureFlag_Domain_Repository_Mapping')
aoekrz marked this conversation as resolved.
Show resolved Hide resolved
->setMethods(['findOneByForeignTableNameAndUid', 'add', 'remove', 'update'])
->getMock();
$mappingRepository->expects($this->never())->method('findOneByForeignTableNameAndUid')->willReturn(null);
$mappingRepository->expects($this->never())->method('add');
$mappingRepository->expects($this->never())->method('remove');
$mappingRepository->expects($this->never())->method('update');
$this->tca->expects($this->never())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->never())->method('getFeatureFlagByUid');

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->getMockBuilder(\TYPO3\CMS\Core\DataHandling\DataHandler::class)->getMock();
$incomingFieldArray = ['hidden' => '0'];
$this->tca->processDatamap_preProcessFieldArray($incomingFieldArray, 'my_table', '4711', $tceMainMock);
}
Expand All @@ -160,17 +162,17 @@ public function processDatamapDoNothingIfNotInFeatureFlagContext()
*/
public function processDatamapRemoveMappingIfNothingSelectedAndMappingExists()
{
$mapping = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping');
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'remove', 'update']
);
$mapping = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_Mapping')->getMock();
$mappingRepository = $this->getMockBuilder(
aoekrz marked this conversation as resolved.
Show resolved Hide resolved
'Tx_FeatureFlag_Domain_Repository_Mapping')
->setMethods(['findOneByForeignTableNameAndUid', 'remove', 'update'])
->getMock();
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn($mapping);
$mappingRepository->expects($this->once())->method('remove');
$mappingRepository->expects($this->once())->method('update');
$this->tca->expects($this->any())->method('getMappingRepository')->willReturn($mappingRepository);

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->getMockBuilder(\TYPO3\CMS\Core\DataHandling\DataHandler::class)->getMock();
$incomingFieldArray = [
'tx_featureflag_flag' => '0',
'tx_featureflag_behavior' => '0',
Expand All @@ -183,20 +185,23 @@ public function processDatamapRemoveMappingIfNothingSelectedAndMappingExists()
*/
public function processDatamapCreateNewMappingIfFeatureFlagGivenAndNoMappingPreviouslyCreated()
{
$featureFlag = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid']);
$featureFlag = $this
->getMockBuilder('Tx_FeatureFlag_Domain_Model_FeatureFlag')
->setMethods(['getUid'])
->getMock();
$featureFlag->expects($this->any())->method('getUid')->willReturn(4711);

$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findOneByForeignTableNameAndUid', 'add']
);
$mappingRepository = $this
->getMockBuilder('Tx_FeatureFlag_Domain_Repository_Mapping')
->setMethods(['findOneByForeignTableNameAndUid', 'add'])
->getMock();
$mappingRepository->expects($this->once())->method('findOneByForeignTableNameAndUid')->willReturn(null);
$mappingRepository->expects($this->once())->method('add');

$this->tca->expects($this->any())->method('getMappingRepository')->willReturn($mappingRepository);
$this->tca->expects($this->any())->method('getFeatureFlagByUid')->willReturn($featureFlag);

$tceMainMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
$tceMainMock = $this->getMockBuilder(\TYPO3\CMS\Core\DataHandling\DataHandler::class)->getMock();
$incomingFieldArray = [
'tx_featureflag_flag' => '4711',
'tx_featureflag_behavior' => '0',
Expand All @@ -218,10 +223,9 @@ public function processCmdmapCommandIsNotDelete()
*/
public function processCmdmappostIsDelete()
{
$mappingRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_Mapping',
['findAllByForeignTableNameAndUid', 'remove']
);
$mappingRepository = $this->getMockBuilder('Tx_FeatureFlag_Domain_Repository_Mapping')
->setMethods(['findAllByForeignTableNameAndUid', 'remove'])
->getMock();
$mappingRepository->expects($this->once())->method('findAllByForeignTableNameAndUid')->willReturn($this->getListOfMappings());
$mappingRepository->expects($this->exactly(2))->method('remove');
$this->tca->expects($this->any())->method('getMappingRepository')->willReturn($mappingRepository);
Expand All @@ -234,9 +238,9 @@ public function processCmdmappostIsDelete()
*/
protected function getListOfMappings()
{
$mapping1 = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping');
$mapping2 = $this->getMock('Tx_FeatureFlag_Domain_Model_Mapping');
$mapping3 = $this->getMock('stdClass');
$mapping1 = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_Mapping')->getMock();
$mapping2 = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_Mapping')->getMock();
$mapping3 = $this->getMockBuilder('stdClass')->getMock();

return array($mapping1, $mapping2, $mapping3);
}
Expand All @@ -246,13 +250,19 @@ protected function getListOfMappings()
*/
protected function getListOfFeatureFlags()
{
$featureFlag1 = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid', 'getDescription']);
$featureFlag1 = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_FeatureFlag')
->setMethods(['getUid', 'getDescription'])
->getMock();
$featureFlag1->expects($this->any())->method('getUid')->willReturn(111);
$featureFlag1->expects($this->any())->method('getDescription')->willReturn('flag 1');
$featureFlag2 = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid', 'getDescription']);
$featureFlag2 = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_FeatureFlag')
->setMethods(['getUid', 'getDescription'])
->getMock();
$featureFlag2->expects($this->any())->method('getUid')->willReturn(4711);
$featureFlag2->expects($this->any())->method('getDescription')->willReturn('flag 2');
$featureFlag3 = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', ['getUid', 'getDescription']);
$featureFlag3 = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_FeatureFlag')
->setMethods(['getUid', 'getDescription'])
->getMock();
$featureFlag3->expects($this->any())->method('getDescription')->willReturn('flag 3');
$featureFlag3->expects($this->any())->method('getUid')->willReturn(222);

Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Domain/Model/MappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function crdate()
*/
public function featureFlag()
{
$featureFlag = $this->getMock('Tx_FeatureFlag_Domain_Model_FeatureFlag', array('getFlag'));
$featureFlag->expects($this->any())->method('getFlag')->will($this->returnValue('my_awesome_feature_flag'));
$featureFlag = $this->getMockBuilder('Tx_FeatureFlag_Domain_Model_FeatureFlag')->setMethods(['getFlag'])->getMock();
$featureFlag->method('getFlag')->willReturn('my_awesome_feature_flag');
$this->mapping->setFeatureFlag($featureFlag);
$this->assertEquals($this->mapping->getFeatureFlag()->getFlag(), 'my_awesome_feature_flag');
}
Expand Down
12 changes: 5 additions & 7 deletions Tests/Unit/Service/EidProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ class EidProcessorTest extends UnitTestCase
*/
private function getServiceMock()
{
return $this->getMock(
'Tx_FeatureFlag_Service', ['updateFeatureFlag'], [], '', false
);
return $this->getMockBuilder(
aoekrz marked this conversation as resolved.
Show resolved Hide resolved
'Tx_FeatureFlag_Service')->setMethods(['updateFeatureFlag'])->disableOriginalConstructor()->getMock();
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function getCacheManagerMock()
{
return $this->getMock(
'Tx_FeatureFlag_System_Typo3_CacheManager', ['clearPageCache'], [], '', false
);
return $this->getMockBuilder(
aoekrz marked this conversation as resolved.
Show resolved Hide resolved
'Tx_FeatureFlag_System_Typo3_CacheManager')->setMethods(['clearPageCache'])->disableOriginalConstructor()->getMock();
}

/**
Expand Down Expand Up @@ -91,7 +89,7 @@ public function shouldThrowExceptionTest()
$_GET = ['action' => '', 'feature' => 'testfeature'];
$eidProcessor = new EidProcessor($this->getServiceMock(), $this->getCacheManagerMock());

$this->setExpectedException(\Tx_FeatureFlag_Service_Exception_ActionNotFound::class);
$this->expectException(\Tx_FeatureFlag_Service_Exception_ActionNotFound::class);
$eidProcessor->processRequest();
}
}
14 changes: 7 additions & 7 deletions Tests/Unit/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Tx_FeatureFlag_Tests_Unit_ServiceTest extends Tx_FeatureFlag_Tests_Unit_Ba
*/
protected function setService(Tx_FeatureFlag_Domain_Repository_FeatureFlag $mockRepository)
{
$mockPersistenceManager = $this->getMock('\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface', array());
$mockPersistenceManager = $this->getMockBuilder('\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface')->getMock();
$this->service = new Tx_FeatureFlag_Service($mockRepository, $mockPersistenceManager, $this->getMockConfiguration());
}

Expand Down Expand Up @@ -76,7 +76,7 @@ private function getMockRepository($isEnabled)
*/
private function getMockConfiguration()
{
$mockConfiguration = $this->getMock('Tx_FeatureFlag_System_Typo3_Configuration', array('getTables'));
$mockConfiguration = $this->getMockBuilder('Tx_FeatureFlag_System_Typo3_Configuration')->setMethods(['getTables'])->getMock();
$mockConfiguration->expects($this->any())->method('getTables')->willReturn('pages');

return $mockConfiguration;
Expand Down Expand Up @@ -122,10 +122,10 @@ public function shouldThrowExceptionIfFlagDoesNotExist()
{
$GLOBALS['TCA']['tx_featureflag_domain_model_featureflag'] = 'mockedTca';

$mockRepository = $this->getMock('Tx_FeatureFlag_Domain_Repository_FeatureFlag', array('findByFlag'));
$mockRepository = $this->getMockBuilder('Tx_FeatureFlag_Domain_Repository_FeatureFlag')->setMethods(['findByFlag'])->getMock();
$mockRepository->expects($this->once())->method('findByFlag')->will($this->returnValue(null));
$this->setService($mockRepository);
$this->setExpectedException('Tx_FeatureFlag_Service_Exception_FeatureNotFound');
$this->expectException('Tx_FeatureFlag_Service_Exception_FeatureNotFound');
$this->service->isFeatureEnabled('my_cool_feature');
}

Expand All @@ -136,10 +136,10 @@ public function shouldThrowExceptionIfTcaIsNotLoaded()
{
$GLOBALS['TCA'] = null;

$mockRepository = $this->getMock('Tx_FeatureFlag_Domain_Repository_FeatureFlag', array('findByFlag'));
$mockRepository = $this->getMockBuilder('Tx_FeatureFlag_Domain_Repository_FeatureFlag')->setMethods(['findByFlag'])->getMock();
$mockRepository->expects($this->never())->method('findByFlag');
$this->setService($mockRepository);
$this->setExpectedException('RuntimeException');
$this->expectException('RuntimeException');
$this->service->isFeatureEnabled('my_cool_feature');
}

Expand All @@ -153,7 +153,7 @@ public function shouldUpdateFeatureFlag()
$mockRepository = $this->getMockRepository(false);
$mockRepository->expects($this->once())->method('update')->with($mockModel);

$mockPersistenceManager = $this->getMock('\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface', array());
$mockPersistenceManager = $this->getMockBuilder('\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface')->getMock();
$mockPersistenceManager->expects($this->once())->method('persistAll');

$serviceMock = $this->getMockBuilder('Tx_FeatureFlag_Service')->setConstructorArgs(array(
Expand Down
8 changes: 3 additions & 5 deletions Tests/Unit/System/Typo3/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ protected function tearDown()
public function methodGetShouldThrowException()
{
$configuration = new Tx_FeatureFlag_System_Typo3_Configuration();
$this->setExpectedException(
'InvalidArgumentException',
'Configuration key "InvalidConfigurationKey" does not exist.',
1384161387
);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Configuration key "InvalidConfigurationKey" does not exist.');
$this->expectExceptionCode(1384161387);
$configuration->get('InvalidConfigurationKey');
}

Expand Down
40 changes: 20 additions & 20 deletions Tests/Unit/System/Typo3/Task/FlagEntriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ class Tx_FeatureFlag_Tests_Unit_System_Typo3_Task_FlagEntriesTest extends Tx_Fea
*/
public function execute()
{
$mockRepository = $this->getMock(
'Tx_FeatureFlag_Domain_Repository_FeatureFlag',
array('updateFeatureFlagStatusForTable')
);
$mockRepository = $this
->getMockBuilder('Tx_FeatureFlag_Domain_Repository_FeatureFlag')
->setMethods(['updateFeatureFlagStatusForTable'])
->getMock();
$mockRepository->expects($this->exactly(2))->method('updateFeatureFlagStatusForTable')->with(
$this->stringStartsWith('table')
);

$mockPersistenceManager = $this->getMock('\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface', array());
$mockPersistenceManager = $this
->getMockBuilder('\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface')->getMock();

$mockConfiguration = $this->getMock('Tx_FeatureFlag_System_Typo3_Configuration', array('getTables'));
$mockConfiguration->expects($this->once())->method('getTables')->will(
$this->returnValue(
array(
'table_one',
'table_two'
)
)
$mockConfiguration = $this
->getMockBuilder('Tx_FeatureFlag_System_Typo3_Configuration')
->setMethods(['getTables'])
->getMock();
$mockConfiguration->expects($this->once())->method('getTables')->willReturn(
[
'table_one',
'table_two'
]
);

$flagEntries = $this->getMock(
'Tx_FeatureFlag_System_Typo3_Task_FlagEntries',
array('getFeatureFlagService'),
array(),
'',
false
);
$flagEntries = $this
->getMockBuilder('Tx_FeatureFlag_System_Typo3_Task_FlagEntries')
->setMethods(['getFeatureFlagService'])
->disableOriginalConstructor()
->getMock();

$serviceMock = $this->getMockBuilder('Tx_FeatureFlag_Service')->setConstructorArgs(array(
$mockRepository,
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
],
"require": {
"php": "^7.0",
"typo3/cms-core": ">=7.6.0",
"ext-json": "*",
"typo3/cms-core": ">=7.6.0, <=8.7.99",
"typo3/cms-extbase": "*",
"typo3/cms-scheduler": "*"
},
"require-dev": {
"typo3/cms": "^7.6",
"nimut/testing-framework": "2.0.*",
"phpunit/phpcov": "3.1.*",
"squizlabs/php_codesniffer": "3.3.*",
"nimut/testing-framework": "^4.1",
"phpunit/phpcov": "4.0.*",
"squizlabs/php_codesniffer": "3.4.*",
"sebastian/phpcpd": "3.0.*",
"phpmd/phpmd": "2.6.*"
},
Expand Down
Loading