From a7714945c667806dcfa20341aabaeba3d6248665 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 9 Dec 2016 19:45:46 +0100 Subject: [PATCH 01/14] FEATURE: Setup first working functional test --- Makefile | 29 ++++++-- .../Fixtures/Indexing/IndexTcaTable.ts | 12 ++++ .../Fixtures/Indexing/IndexTcaTable.xml | 69 +++++++++++++++++++ Tests/Functional/FunctionalTestCase.php | 56 +++++++++++++++ Tests/Functional/FunctionalTests.xml | 22 ++++++ .../Functional/Indexing/IndexTcaTableTest.php | 56 +++++++++++++++ 6 files changed, 237 insertions(+), 7 deletions(-) create mode 100644 Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts create mode 100644 Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml create mode 100644 Tests/Functional/FunctionalTestCase.php create mode 100644 Tests/Functional/FunctionalTests.xml create mode 100644 Tests/Functional/Indexing/IndexTcaTableTest.php diff --git a/Makefile b/Makefile index ef9b947..92aeffc 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,33 @@ current_dir := $(dir $(mkfile_path)) TYPO3_WEB_DIR := $(current_dir).Build/Web # Allow different versions on travis -TYPO3_VERSION ?= ~6.2 +TYPO3_VERSION ?= ~6.2.19 +typo3DatabaseName ?= "test" +typo3DatabaseUsername ?= "dev" +typo3DatabasePassword ?= "dev" +typo3DatabaseHost ?= "127.0.0.1" .PHONY: install install: - rm -rf .Build - - composer require --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" - composer update -vv + rm .Build + COMPOSER_PROCESS_TIMEOUT=1000 composer require -vvv --dev typo3/cms="$(TYPO3_VERSION)" git checkout composer.json mkdir -p $(TYPO3_WEB_DIR)/uploads $(TYPO3_WEB_DIR)/typo3temp +unitTests: + TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) \ + .Build/bin/phpunit --colors --debug -v \ + -c Tests/Unit/UnitTests.xml + +functionalTests: + typo3DatabaseName=$(typo3DatabaseName) \ + typo3DatabaseUsername=$(typo3DatabaseUsername) \ + typo3DatabasePassword=$(typo3DatabasePassword) \ + typo3DatabaseHost=$(typo3DatabaseHost) \ + TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) \ + .Build/bin/phpunit --colors --debug -v \ + -c Tests/Functional/FunctionalTests.xml + .PHONY: Tests -Tests: - TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) .Build/bin/phpunit --colors --debug -v -c Tests/Unit/UnitTests.xml +Tests: unitTests functionalTests diff --git a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts new file mode 100644 index 0000000..22c4ed8 --- /dev/null +++ b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts @@ -0,0 +1,12 @@ +plugin { + tx_searchcore { + settings { + connection { + host = localhost + port = 9200 + } + } + } +} + +module.tx_searchcore < plugin.tx_searchcore diff --git a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml new file mode 100644 index 0000000..50532f2 --- /dev/null +++ b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml @@ -0,0 +1,69 @@ + + + + 1 + 0 + Page Title + + + + 6 + 1 + 1480686370 + 1480686370 + 0 + 72 + textmedia +
test
+ this is the content of textmedia content element that should get indexed + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +
+ + + 7 + 1 + 1480686371 + 1480686370 + 0 + 72 + textmedia +
endtime hidden record
+ + 0 + 0 + 0 + 0 + 0 + 1481305963 + 0 + 0 +
+ + + 8 + 1 + 1480686370 + 1480686370 + 1 + 72 + textmedia +
Hidden record
+ + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +
+ +
diff --git a/Tests/Functional/FunctionalTestCase.php b/Tests/Functional/FunctionalTestCase.php new file mode 100644 index 0000000..bd04468 --- /dev/null +++ b/Tests/Functional/FunctionalTestCase.php @@ -0,0 +1,56 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use TYPO3\CMS\Core\Tests\FunctionalTestCase as CoreTestCase; + +/** + * All functional tests should extend this base class. + * + * It will take care of leaving a clean environment for next test. + */ +abstract class FunctionalTestCase extends CoreTestCase +{ + protected $testExtensionsToLoad = ['typo3conf/ext/search_core']; + + /** + * @var \Elastica\Client + */ + protected $client; + + public function setUp() + { + parent::setUp(); + + // Create client to make requests and assert something. + $this->client = new \Elastica\Client([ + 'host' => getenv('ES_HOST') ?: \Elastica\Connection::DEFAULT_HOST, + 'port' => getenv('ES_PORT') ?: \Elastica\Connection::DEFAULT_PORT, + ]); + } + + public function tearDown() + { + // Delete everything so next test starts clean. + $this->client->getIndex('_all')->delete(); + $this->client->getIndex('_all')->clearCache(); + } +} diff --git a/Tests/Functional/FunctionalTests.xml b/Tests/Functional/FunctionalTests.xml new file mode 100644 index 0000000..466358e --- /dev/null +++ b/Tests/Functional/FunctionalTests.xml @@ -0,0 +1,22 @@ + + + + + . + + + diff --git a/Tests/Functional/Indexing/IndexTcaTableTest.php b/Tests/Functional/Indexing/IndexTcaTableTest.php new file mode 100644 index 0000000..57a6df6 --- /dev/null +++ b/Tests/Functional/Indexing/IndexTcaTableTest.php @@ -0,0 +1,56 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Leonmrni\SearchCore\Domain\Index\IndexerFactory; +use Leonmrni\SearchCore\Tests\Functional\FunctionalTestCase; +use TYPO3\CMS\Extbase\Object\ObjectManager; + +/** + * + */ +class IndexTcaTableTest extends FunctionalTestCase +{ + public function setUp() + { + parent::setUp(); + + $this->importDataSet('Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml'); + $this->setUpFrontendRootPage(1, ['EXT:search_core/Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts']); + } + + /** + * @test + */ + public function indexBasicTtContentWithoutBasicConfiguration() + { + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) + ->get(IndexerFactory::class) + ->getIndexer('tt_content') + ->index() + ; + + $response = $this->client->request('typo3content/_search?q=*:*'); + + $this->assertTrue($response->isOK()); + $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); + } +} From 3bd2b9c52d16069693049fb8357b9c1677eebd2d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 9 Dec 2016 19:50:53 +0100 Subject: [PATCH 02/14] WIP|FEATURE: Integrate functional tests into travis --- .travis.yml | 10 ++++++++++ Makefile | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a7ae7b..cef088d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,11 @@ php: - 7.0 env: + global: + - TYPO3_DATABASE_NAME="typo3_ci" + - TYPO3_DATABASE_HOST="127.0.0.1" + - TYPO3_DATABASE_USERNAME="root" + - TYPO3_DATABASE_PASSWORD="" matrix: - TYPO3_VERSION="~6.2" - TYPO3_VERSION="~7.6" @@ -22,9 +27,14 @@ matrix: - env: TYPO3_VERSION="dev-master" php: 5.6 +services: + - mysql-5.6 + - elasticsearch-5.0 + before_install: - composer self-update - composer --version + - mysql -u root -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('')" install: - make install diff --git a/Makefile b/Makefile index 92aeffc..0eeb8ed 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ typo3DatabaseHost ?= "127.0.0.1" .PHONY: install install: rm .Build - COMPOSER_PROCESS_TIMEOUT=1000 composer require -vvv --dev typo3/cms="$(TYPO3_VERSION)" + COMPOSER_PROCESS_TIMEOUT=1000 composer require -vvv --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" git checkout composer.json mkdir -p $(TYPO3_WEB_DIR)/uploads $(TYPO3_WEB_DIR)/typo3temp From 8dc373c0b2e94705f90c636309839114e14f57cf Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 9 Dec 2016 19:57:23 +0100 Subject: [PATCH 03/14] BUGFIX: Don't break travis because folder does not exist --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0eeb8ed..4424ee7 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ typo3DatabaseHost ?= "127.0.0.1" .PHONY: install install: - rm .Build + rm -rf .Build COMPOSER_PROCESS_TIMEOUT=1000 composer require -vvv --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" git checkout composer.json From 4ff23c60c20e4b77d50692bbd97b52474841bec6 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 9 Dec 2016 20:00:42 +0100 Subject: [PATCH 04/14] WIP|FEATURE: Try to make functional tests work on travis --- .travis.yml | 18 +++++++++--------- Makefile | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index cef088d..9ad936a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,14 +2,19 @@ language: php php: - 5.6 - - 7.0 + # Elastica is not compatible yet, see https://travis-ci.org/DanielSiepmann/search_core/jobs/182692743 + # - 7.0 env: global: - TYPO3_DATABASE_NAME="typo3_ci" - TYPO3_DATABASE_HOST="127.0.0.1" - - TYPO3_DATABASE_USERNAME="root" + - TYPO3_DATABASE_USERNAME="travis" - TYPO3_DATABASE_PASSWORD="" + - typo3DatabaseName="typo3_ci" + - typo3DatabaseHost="127.0.0.1" + - typo3DatabaseUsername="travis" + - typo3DatabasePassword="" matrix: - TYPO3_VERSION="~6.2" - TYPO3_VERSION="~7.6" @@ -28,13 +33,8 @@ matrix: php: 5.6 services: - - mysql-5.6 - - elasticsearch-5.0 - -before_install: - - composer self-update - - composer --version - - mysql -u root -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('')" + - mysql + - elasticsearch install: - make install diff --git a/Makefile b/Makefile index 4424ee7..fbf1b18 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ typo3DatabaseHost ?= "127.0.0.1" .PHONY: install install: rm -rf .Build - COMPOSER_PROCESS_TIMEOUT=1000 composer require -vvv --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" + COMPOSER_PROCESS_TIMEOUT=1000 composer require -vv --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" git checkout composer.json mkdir -p $(TYPO3_WEB_DIR)/uploads $(TYPO3_WEB_DIR)/typo3temp From c3763a0982e380bb68c87ca622f57e4220a92d14 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 10 Dec 2016 13:59:34 +0100 Subject: [PATCH 05/14] FEATURE: Use latest stable elastica version (#5) * As we should use it anyway. * It's compatible with PHP 7 * Also we added php 7.1 to travis --- .travis.yml | 25 ++++++++++++++----------- composer.json | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ad936a..2cb95f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: php php: - 5.6 - # Elastica is not compatible yet, see https://travis-ci.org/DanielSiepmann/search_core/jobs/182692743 - # - 7.0 + - 7.0 + - 7.1 env: global: @@ -22,25 +22,28 @@ env: matrix: fast_finish: true - allow_failures: - - env: TYPO3_VERSION="~6.2" - php: 7.0 - - env: TYPO3_VERSION="dev-master" - php: 7.0 exclude: # TYPO3 no longer supports 5.6 - env: TYPO3_VERSION="dev-master" php: 5.6 + # There is some error with 6.2 and 7 not finding the "UnitTestsBootstrap.php" + - env: TYPO3_VERSION="~6.2" + php: 7.0 + - env: TYPO3_VERSION="~6.2" + php: 7.1 + allow_failures: + - env: TYPO3_VERSION="dev-master" + php: 7.0 + - env: TYPO3_VERSION="dev-master" + php: 7.1 services: - mysql - elasticsearch -install: - - make install +install: make install -script: - - make Tests +script: make Tests cache: directories: diff --git a/composer.json b/composer.json index 8ac7521..be5051e 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ }, "require" : { "php": ">=5.6.0", - "typo3/cms": ">=6.2.0", - "ruflin/elastica": "~1.4" + "typo3/cms": "~6.2", + "ruflin/elastica": "~3.2" }, "require-dev": { "phpunit/phpunit": "~4.8.0" From 67463fa13536d99482b6230fe7ec7b359003a51a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 10 Dec 2016 14:41:48 +0100 Subject: [PATCH 06/14] TASK: Refactor tests * Have necessary setup in all tests. * Added todos --- .../Fixtures/{Indexing/IndexTcaTable.ts => BasicSetup.ts} | 0 Tests/Functional/Fixtures/BasicSetup.xml | 8 ++++++++ Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml | 6 ------ Tests/Functional/FunctionalTestCase.php | 4 ++++ Tests/Functional/Indexing/IndexTcaTableTest.php | 5 ++++- 5 files changed, 16 insertions(+), 7 deletions(-) rename Tests/Functional/Fixtures/{Indexing/IndexTcaTable.ts => BasicSetup.ts} (100%) create mode 100644 Tests/Functional/Fixtures/BasicSetup.xml diff --git a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts b/Tests/Functional/Fixtures/BasicSetup.ts similarity index 100% rename from Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts rename to Tests/Functional/Fixtures/BasicSetup.ts diff --git a/Tests/Functional/Fixtures/BasicSetup.xml b/Tests/Functional/Fixtures/BasicSetup.xml new file mode 100644 index 0000000..a85b72a --- /dev/null +++ b/Tests/Functional/Fixtures/BasicSetup.xml @@ -0,0 +1,8 @@ + + + + 1 + 0 + Root page containing necessary TypoScript + + diff --git a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml index 50532f2..14ef723 100644 --- a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml +++ b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml @@ -1,11 +1,5 @@ - - 1 - 0 - Page Title - - 6 1 diff --git a/Tests/Functional/FunctionalTestCase.php b/Tests/Functional/FunctionalTestCase.php index bd04468..a329ca4 100644 --- a/Tests/Functional/FunctionalTestCase.php +++ b/Tests/Functional/FunctionalTestCase.php @@ -40,6 +40,10 @@ abstract class FunctionalTestCase extends CoreTestCase { parent::setUp(); + // Provide necessary configuration for extension + $this->importDataSet('Tests/Functional/Fixtures/BasicSetup.xml'); + $this->setUpFrontendRootPage(1, ['EXT:search_core/Tests/Functional/Fixtures/BasicSetup.ts']); + // Create client to make requests and assert something. $this->client = new \Elastica\Client([ 'host' => getenv('ES_HOST') ?: \Elastica\Connection::DEFAULT_HOST, diff --git a/Tests/Functional/Indexing/IndexTcaTableTest.php b/Tests/Functional/Indexing/IndexTcaTableTest.php index 57a6df6..7a6d355 100644 --- a/Tests/Functional/Indexing/IndexTcaTableTest.php +++ b/Tests/Functional/Indexing/IndexTcaTableTest.php @@ -34,7 +34,6 @@ class IndexTcaTableTest extends FunctionalTestCase parent::setUp(); $this->importDataSet('Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml'); - $this->setUpFrontendRootPage(1, ['EXT:search_core/Tests/Functional/Fixtures/Indexing/IndexTcaTable.ts']); } /** @@ -53,4 +52,8 @@ class IndexTcaTableTest extends FunctionalTestCase $this->assertTrue($response->isOK()); $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); } + + // TODO: Add tests for hook. + + // TODO: Add tests for search in frontend. } From 070e901dbb531d4948d7ed3d18b5e02021a9a499 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 10 Dec 2016 14:59:48 +0100 Subject: [PATCH 07/14] FEATURE: Add code coverage for tests to travis and scrutinizer (#6) * FEATURE: Add code coverage for tests to travis and scrutinizer * To detect which parts still need to be tested * BUGFIX: Fix broken TYPO3 installation for tests * We need the source, otherwise a base test file will be missing --- .scrutinizer.yml | 4 ++++ .travis.yml | 6 ++++++ Makefile | 8 ++++---- Tests/Functional/FunctionalTests.xml | 12 ++++++++++++ Tests/Unit/UnitTests.xml | 12 ++++++++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 7cbd254..56b321e 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -32,3 +32,7 @@ tools: php_analyzer: enabled: true + # We generate code coverage during tests at travis and will send them here + external_code_coverage: + runs: 2 + timeout: 1200 diff --git a/.travis.yml b/.travis.yml index 2cb95f9..84984ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,6 +45,12 @@ install: make install script: make Tests +after_script: + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover .Build/report/unit/clover/coverage + - php ocular.phar code-coverage:upload --format=php-clover .Build/report/functional/clover/coverage + - make clean + cache: directories: - $HOME/.composer/cache diff --git a/Makefile b/Makefile index fbf1b18..7fe83d5 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,9 @@ typo3DatabasePassword ?= "dev" typo3DatabaseHost ?= "127.0.0.1" .PHONY: install -install: - rm -rf .Build +install: clean COMPOSER_PROCESS_TIMEOUT=1000 composer require -vv --dev --prefer-source typo3/cms="$(TYPO3_VERSION)" - git checkout composer.json - mkdir -p $(TYPO3_WEB_DIR)/uploads $(TYPO3_WEB_DIR)/typo3temp unitTests: TYPO3_PATH_WEB=$(TYPO3_WEB_DIR) \ @@ -33,3 +30,6 @@ functionalTests: .PHONY: Tests Tests: unitTests functionalTests + +clean: + rm -rf .Build composer.lock diff --git a/Tests/Functional/FunctionalTests.xml b/Tests/Functional/FunctionalTests.xml index 466358e..07d6f87 100644 --- a/Tests/Functional/FunctionalTests.xml +++ b/Tests/Functional/FunctionalTests.xml @@ -19,4 +19,16 @@ . + + + + ../../Classes + + + + + + + + diff --git a/Tests/Unit/UnitTests.xml b/Tests/Unit/UnitTests.xml index 93247f4..63627f9 100644 --- a/Tests/Unit/UnitTests.xml +++ b/Tests/Unit/UnitTests.xml @@ -19,4 +19,16 @@ . + + + + ../../Classes + + + + + + + + From 8500b8fd5717a4b3692869fc0222350a5331c032 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 10 Dec 2016 16:20:37 +0100 Subject: [PATCH 08/14] BUGFIX: Separate functional and unit coverage results --- Tests/Functional/FunctionalTests.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Functional/FunctionalTests.xml b/Tests/Functional/FunctionalTests.xml index 07d6f87..44a3f8f 100644 --- a/Tests/Functional/FunctionalTests.xml +++ b/Tests/Functional/FunctionalTests.xml @@ -1,5 +1,5 @@ - - + + From 31c4108039ce0957dc8b7ee238fe060094c512a8 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sat, 10 Dec 2016 16:21:02 +0100 Subject: [PATCH 09/14] FEATURE: Add two more tests for indexing --- .../Functional/Indexing/IndexTcaTableTest.php | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Tests/Functional/Indexing/IndexTcaTableTest.php b/Tests/Functional/Indexing/IndexTcaTableTest.php index 7a6d355..96d113f 100644 --- a/Tests/Functional/Indexing/IndexTcaTableTest.php +++ b/Tests/Functional/Indexing/IndexTcaTableTest.php @@ -53,7 +53,38 @@ class IndexTcaTableTest extends FunctionalTestCase $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); } - // TODO: Add tests for hook. + /** + * @test + * @expectedException \Leonmrni\SearchCore\Domain\Index\IndexingException + */ + public function indexingNonConfiguredTableWillThrowException() + { + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) + ->get(IndexerFactory::class) + ->getIndexer('non_existing_table') + ; + } - // TODO: Add tests for search in frontend. + /** + * @test + */ + public function canHandleExisingIndex() + { + $indexer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class) + ->get(IndexerFactory::class) + ->getIndexer('tt_content') + ; + + $indexer->index(); + + // Index 2nd time, index already exists in elasticsearch. + $indexer->index(); + + $response = $this->client->request('typo3content/_search?q=*:*'); + + $this->assertTrue($response->isOK()); + $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); + } + + // TODO: Add tests for hook. } From 62ce1974062441eedeb8268e90871c87afb944c5 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 12 Dec 2016 13:33:07 +0100 Subject: [PATCH 10/14] FEATURE: Added tests for hook and implemented logic (#8) * FEATURE: Added tests for hook and implemented logic * To enable updating search index on modifications through TYPO3 API. * BUGFIX: Fix path for unit test coverage report * To fix failing delivery to scrutinizer. --- Classes/Connection/Elasticsearch.php | 63 +++++++--- Classes/Domain/Index/IndexerInterface.php | 7 ++ Classes/Domain/Index/TcaIndexer.php | 23 ++++ Classes/Domain/Service/DataHandler.php | 30 +++-- Classes/Hook/DataHandler.php | 12 +- Classes/Service/DataHandler.php | 80 ------------- .../Functional/Fixtures/Hooks/DataHandler.xml | 22 ++++ Tests/Functional/Hooks/DataHandlerTest.php | 110 ++++++++++++++++++ .../Functional/Indexing/IndexTcaTableTest.php | 2 - Tests/Unit/UnitTests.xml | 4 +- 10 files changed, 240 insertions(+), 113 deletions(-) delete mode 100644 Classes/Service/DataHandler.php create mode 100644 Tests/Functional/Fixtures/Hooks/DataHandler.xml create mode 100644 Tests/Functional/Hooks/DataHandlerTest.php diff --git a/Classes/Connection/Elasticsearch.php b/Classes/Connection/Elasticsearch.php index 3c518e7..82945a6 100644 --- a/Classes/Connection/Elasticsearch.php +++ b/Classes/Connection/Elasticsearch.php @@ -82,17 +82,32 @@ class Elasticsearch implements Singleton, ConnectionInterface public function add($documentType, array $document) { - throw new \Exception('Implement', 1481190734); + $this->withType( + $documentType, + function ($type) use($document) { + $type->addDocument($this->documentFactory->getDocument($documentType, $document)); + } + ); } public function delete($documentType, $identifier) { - throw new \Exception('Implement', 1481190734); + $this->withType( + $documentType, + function ($type) use($identifier) { + $type->deleteById($identifier); + } + ); } public function update($documentType, array $document) { - throw new \Exception('Implement', 1481190734); + $this->withType( + $documentType, + function ($type) use($documentType) { + $type->updateDocument($this->documentFactory->getDocument($documentType, $document)); + } + ); } /** @@ -103,18 +118,24 @@ class Elasticsearch implements Singleton, ConnectionInterface */ public function addDocuments($documentType, array $documents) { - $type = $this->typeFactory->getType( - $this->indexFactory->getIndex( - $this->connection, - $documentType - ), - $documentType - ); - - $type->addDocuments( - $this->documentFactory->getDocuments($documentType, $documents) + $this->withType( + $documentType, + function ($type) use($documents) { + $type->addDocuments($this->documentFactory->getDocuments($documentType, $documents)); + } ); + } + /** + * Execute given callback with Elastica Type based on provided documentType + * + * @param string $documentType + * @param callable $callback + */ + protected function withType($documentType, callable $callback) + { + $type = $this->getType($documentType); + $callback($type); $type->getIndex()->refresh(); } @@ -132,4 +153,20 @@ class Elasticsearch implements Singleton, ConnectionInterface // TODO: Return wrapped result to implement our interface. return $search->search($searchRequest->getSearchTerm()); } + + /** + * @param string $documentType + * + * @return \Elastica\Type + */ + protected function getType($documentType) + { + return $this->typeFactory->getType( + $this->indexFactory->getIndex( + $this->connection, + $documentType + ), + $documentType + ); + } } diff --git a/Classes/Domain/Index/IndexerInterface.php b/Classes/Domain/Index/IndexerInterface.php index af5ceca..88972dd 100644 --- a/Classes/Domain/Index/IndexerInterface.php +++ b/Classes/Domain/Index/IndexerInterface.php @@ -31,4 +31,11 @@ interface IndexerInterface * @return void */ public function index(); + + /** + * Index a single record. + * + * @return void + */ + public function indexRecord($identifier); } diff --git a/Classes/Domain/Index/TcaIndexer.php b/Classes/Domain/Index/TcaIndexer.php index 7e6671a..0205836 100644 --- a/Classes/Domain/Index/TcaIndexer.php +++ b/Classes/Domain/Index/TcaIndexer.php @@ -75,6 +75,13 @@ class TcaIndexer implements IndexerInterface $this->logger->info('Finish indexing'); } + public function indexRecord($identifier) + { + $this->logger->info('Start indexing single record.', [$identifier]); + $this->connection->add($this->tcaTableService->getTableName(), $this->getRecord($identifier)); + $this->logger->info('Finish indexing'); + } + /** * @return \Generator */ @@ -114,4 +121,20 @@ class TcaIndexer implements IndexerInterface return $records; } + + /** + * @param int $identifier + * @return array + */ + protected function getRecord($identifier) + { + $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( + $this->tcaTableService->getFields(), + $this->tcaTableService->getTableName(), + $this->tcaTableService->getWhereClause() . ' AND uid = ' . (int) $identifier + ); + $this->tcaTableService->prepareRecord($record); + + return $record; + } } diff --git a/Classes/Domain/Service/DataHandler.php b/Classes/Domain/Service/DataHandler.php index 66913e1..6446979 100644 --- a/Classes/Domain/Service/DataHandler.php +++ b/Classes/Domain/Service/DataHandler.php @@ -36,6 +36,12 @@ class DataHandler implements Singleton */ protected $connection; + /** + * @var \Leonmrni\SearchCore\Domain\Index\IndexerFactory + * @inject + */ + protected $indexerFactory; + /** * @var \TYPO3\CMS\Core\Log\Logger */ @@ -51,16 +57,6 @@ class DataHandler implements Singleton $this->logger = $logManager->getLogger(__CLASS__); } - /** - * @param string $table - * @param int $identifier - */ - public function delete($table, $identifier) - { - $this->logger->debug('Record received for delete.', [$table, $identifier]); - $this->connection->delete($table, $identifier); - } - /** * @param string $table * @param array $record @@ -68,7 +64,7 @@ class DataHandler implements Singleton public function add($table, array $record) { $this->logger->debug('Record received for add.', [$table, $record]); - $this->connection->add($table, $record); + $this->indexerFactory->getIndexer($table)->indexRecord($record['uid']); } /** @@ -77,6 +73,16 @@ class DataHandler implements Singleton public function update($table, array $record) { $this->logger->debug('Record received for update.', [$table, $record]); - $this->connection->update($table, $record); + $this->indexerFactory->getIndexer($table)->indexRecord($record['uid']); + } + + /** + * @param string $table + * @param int $identifier + */ + public function delete($table, $identifier) + { + $this->logger->debug('Record received for delete.', [$table, $identifier]); + $this->connection->delete($table, $identifier); } } diff --git a/Classes/Hook/DataHandler.php b/Classes/Hook/DataHandler.php index a413aa2..c085d90 100644 --- a/Classes/Hook/DataHandler.php +++ b/Classes/Hook/DataHandler.php @@ -74,12 +74,14 @@ class DataHandler implements Singleton * * @param string $table * @param int $uid + * + * @return bool False if hook was not processed. */ public function processCmdmap_deleteAction($table, $uid) { if (! $this->shouldProcessTable($table)) { $this->logger->debug('Delete not processed, cause table is not allowed.', [$table]); - return; + return false; } $this->dataHandler->delete($table, $uid); @@ -93,18 +95,20 @@ class DataHandler implements Singleton * @param string|int $uid * @param array $fieldArray * @param CoreDataHandler $dataHandler + * + * @return bool False if hook was not processed. */ public function processDatamap_afterDatabaseOperations($status, $table, $uid, array $fieldArray, CoreDataHandler $dataHandler) { if (! $this->shouldProcessTable($table)) { $this->logger->debug('Database update not processed, cause table is not allowed.', [$table]); - return; + return false; } if ($status === 'new') { $fieldArray['uid'] = $dataHandler->substNEWwithIDs[$uid]; $this->dataHandler->add($table, $fieldArray); - return; + return false; } if ($status === 'update') { @@ -112,7 +116,7 @@ class DataHandler implements Singleton if ($record !== null) { $this->dataHandler->update($table, $record); } - return; + return false; } $this->logger->debug( diff --git a/Classes/Service/DataHandler.php b/Classes/Service/DataHandler.php deleted file mode 100644 index 0febc5a..0000000 --- a/Classes/Service/DataHandler.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -use TYPO3\CMS\Core\SingletonInterface as Singleton; - -/** - * Handles all data related things like updates, deletes and inserts. - * - * This is the place to add mappings of further parts to adjust the data before - * sending ot to connection. - */ -class DataHandler implements Singleton -{ - /** - * @var \TYPO3\CMS\Core\Log\Logger - */ - protected $logger; - - // TODO: Write construct with inject of connection - - /** - * Inject log manager to get concrete logger from it. - * - * @param \TYPO3\CMS\Core\Log\LogManager $logManager - */ - public function injectLogger(\TYPO3\CMS\Core\Log\LogManager $logManager) - { - $this->logger = $logManager->getLogger(__CLASS__); - } - - /** - * @param string $table - * @param int $identifier - */ - public function delete($table, $identifier) - { - $this->logger->debug('Record received for delete.', [$table, $identifier]); - // $this->connection->delete($table, $identifier); - } - - /** - * @param string $table - * @param int $identifier - * @param array $record - */ - public function add($table, $identifier, array $record) - { - $this->logger->debug('Record received for add.', [$table, $identifier, $record]); - // $this->connection->add($table, $identifier, $record); - } - - /** - * @param string $table - * @param int $identifier - */ - public function update($table, $identifier, array $record) - { - $this->logger->debug('Record received for update.', [$table, $identifier, $record]); - // $this->connection->update($table, $identifier, $record); - } -} diff --git a/Tests/Functional/Fixtures/Hooks/DataHandler.xml b/Tests/Functional/Fixtures/Hooks/DataHandler.xml new file mode 100644 index 0000000..db3f5ba --- /dev/null +++ b/Tests/Functional/Fixtures/Hooks/DataHandler.xml @@ -0,0 +1,22 @@ + + + + 6 + 1 + 1480686370 + 1480686370 + 0 + 72 + textmedia +
test
+ this is the content of textmedia content element that should get indexed + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +
+
diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php new file mode 100644 index 0000000..9ca4326 --- /dev/null +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -0,0 +1,110 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Leonmrni\SearchCore\Hook\DataHandler as Hook; +use Leonmrni\SearchCore\Tests\Functional\FunctionalTestCase; +use TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler; +use TYPO3\CMS\Extbase\Object\ObjectManager; + +/** + * + */ +class DataHandlerTest extends FunctionalTestCase +{ + public function setUp() + { + parent::setUp(); + $this->importDataSet('Tests/Functional/Fixtures/Hooks/DataHandler.xml'); + } + + /** + * @test + */ + public function nonAllowedTablesWillNotBeProcessed() + { + $dataHandler = new CoreDataHandler(); + + $hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class); + $this->assertFalse($hook->processDatamap_afterDatabaseOperations('new', 'some_strange_table', 'NEW34', [], $dataHandler)); + $this->assertFalse($hook->processDatamap_afterDatabaseOperations('update', 'some_strange_table', 6, [], $dataHandler)); + $this->assertFalse($hook->processCmdmap_deleteAction('some_strange_table', 6, [], false, $dataHandler)); + } + + /** + * @test + */ + public function addNewElement() + { + $dataHandler = new CoreDataHandler(); + $dataHandler->substNEWwithIDs = ['NEW34' => 6]; + + $hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class); + $hook->processDatamap_afterDatabaseOperations('new', 'tt_content', 'NEW34', [], $dataHandler); + + $response = $this->client->request('typo3content/_search?q=*:*'); + $this->assertTrue($response->isOK()); + $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); + } + + /** + * @test + * TODO: Make sure the indexed document was updated, e.g. by changing some content. + */ + public function updateExistingElement() + { + $dataHandler = new CoreDataHandler(); + $hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class); + $hook->processDatamap_afterDatabaseOperations('update', 'tt_content', 6, [], $dataHandler); + + $response = $this->client->request('typo3content/_search?q=*:*'); + $this->assertTrue($response->isOK()); + $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); + } + + /** + * @test + */ + public function deleteExistingElement() + { + $this->addNewElement(); + $dataHandler = new CoreDataHandler(); + $hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class); + $hook->processCmdmap_deleteAction('tt_content', 6, [], false, $dataHandler); + + $response = $this->client->request('typo3content/_search?q=*:*'); + $this->assertTrue($response->isOK()); + $this->assertSame($response->getData()['hits']['total'], 0, 'Not exactly 0 document was indexed.'); + } + + /** + * @test + * @expectedException \Elastica\Exception\ResponseException + */ + public function someUnkownOperationDoesNotBreakSomething() + { + $dataHandler = new CoreDataHandler(); + $hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class); + $hook->processDatamap_afterDatabaseOperations('something', 'tt_content', 6, [], $dataHandler); + + $response = $this->client->request('typo3content/_search?q=*:*'); + } +} diff --git a/Tests/Functional/Indexing/IndexTcaTableTest.php b/Tests/Functional/Indexing/IndexTcaTableTest.php index 96d113f..fc2ce65 100644 --- a/Tests/Functional/Indexing/IndexTcaTableTest.php +++ b/Tests/Functional/Indexing/IndexTcaTableTest.php @@ -85,6 +85,4 @@ class IndexTcaTableTest extends FunctionalTestCase $this->assertTrue($response->isOK()); $this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.'); } - - // TODO: Add tests for hook. } diff --git a/Tests/Unit/UnitTests.xml b/Tests/Unit/UnitTests.xml index 63627f9..67719fc 100644 --- a/Tests/Unit/UnitTests.xml +++ b/Tests/Unit/UnitTests.xml @@ -27,8 +27,8 @@ - - + + From 1692a02c55ad23ecf9b4be079974ec829a699746 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 12 Dec 2016 18:02:52 +0100 Subject: [PATCH 11/14] CLENAUP: Remove some scrutinizer ci issues --- Classes/Connection/Elasticsearch.php | 15 ++++++++------- Classes/Hook/DataHandler.php | 4 +++- ...estCase.php => AbstractFunctionalTestCase.php} | 4 +++- Tests/Functional/Hooks/DataHandlerTest.php | 4 ++-- Tests/Functional/Indexing/IndexTcaTableTest.php | 4 ++-- 5 files changed, 18 insertions(+), 13 deletions(-) rename Tests/Functional/{FunctionalTestCase.php => AbstractFunctionalTestCase.php} (95%) diff --git a/Classes/Connection/Elasticsearch.php b/Classes/Connection/Elasticsearch.php index 82945a6..49d169b 100644 --- a/Classes/Connection/Elasticsearch.php +++ b/Classes/Connection/Elasticsearch.php @@ -84,8 +84,8 @@ class Elasticsearch implements Singleton, ConnectionInterface { $this->withType( $documentType, - function ($type) use($document) { - $type->addDocument($this->documentFactory->getDocument($documentType, $document)); + function ($type) use ($document) { + $type->addDocument($this->documentFactory->getDocument($type->getName(), $document)); } ); } @@ -104,8 +104,8 @@ class Elasticsearch implements Singleton, ConnectionInterface { $this->withType( $documentType, - function ($type) use($documentType) { - $type->updateDocument($this->documentFactory->getDocument($documentType, $document)); + function ($type) use ($document) { + $type->updateDocument($this->documentFactory->getDocument($type->getName(), $document)); } ); } @@ -120,8 +120,8 @@ class Elasticsearch implements Singleton, ConnectionInterface { $this->withType( $documentType, - function ($type) use($documents) { - $type->addDocuments($this->documentFactory->getDocuments($documentType, $documents)); + function ($type) use ($documents) { + $type->addDocuments($this->documentFactory->getDocuments($type->getName(), $documents)); } ); } @@ -141,7 +141,7 @@ class Elasticsearch implements Singleton, ConnectionInterface /** * @param SearchRequestInterface $searchRequest - * @return SearchResultInterface + * @return \Elastica\ResultSet */ public function search(SearchRequestInterface $searchRequest) { @@ -151,6 +151,7 @@ class Elasticsearch implements Singleton, ConnectionInterface $search->addIndex('typo3content'); // TODO: Return wrapped result to implement our interface. + // Also update php doc to reflect the change. return $search->search($searchRequest->getSearchTerm()); } diff --git a/Classes/Hook/DataHandler.php b/Classes/Hook/DataHandler.php index c085d90..a49b454 100644 --- a/Classes/Hook/DataHandler.php +++ b/Classes/Hook/DataHandler.php @@ -85,6 +85,7 @@ class DataHandler implements Singleton } $this->dataHandler->delete($table, $uid); + return true; } /** @@ -123,6 +124,7 @@ class DataHandler implements Singleton 'Database update not processed, cause status is unhandled.', [$status, $table, $uid, $fieldArray] ); + return true; } /** @@ -153,7 +155,7 @@ class DataHandler implements Singleton * * @param string $table * @param int $uid - * @return null|array + * @return null|array */ protected function getRecord($table, $uid) { diff --git a/Tests/Functional/FunctionalTestCase.php b/Tests/Functional/AbstractFunctionalTestCase.php similarity index 95% rename from Tests/Functional/FunctionalTestCase.php rename to Tests/Functional/AbstractFunctionalTestCase.php index a329ca4..743b4cc 100644 --- a/Tests/Functional/FunctionalTestCase.php +++ b/Tests/Functional/AbstractFunctionalTestCase.php @@ -27,7 +27,7 @@ use TYPO3\CMS\Core\Tests\FunctionalTestCase as CoreTestCase; * * It will take care of leaving a clean environment for next test. */ -abstract class FunctionalTestCase extends CoreTestCase +abstract class AbstractFunctionalTestCase extends CoreTestCase { protected $testExtensionsToLoad = ['typo3conf/ext/search_core']; @@ -54,7 +54,9 @@ abstract class FunctionalTestCase extends CoreTestCase public function tearDown() { // Delete everything so next test starts clean. + if ($this->client) { $this->client->getIndex('_all')->delete(); $this->client->getIndex('_all')->clearCache(); + } } } diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index 9ca4326..f64fbd6 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -21,14 +21,14 @@ namespace Leonmrni\SearchCore\Tests\Functional\Hooks; */ use Leonmrni\SearchCore\Hook\DataHandler as Hook; -use Leonmrni\SearchCore\Tests\Functional\FunctionalTestCase; +use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase; use TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler; use TYPO3\CMS\Extbase\Object\ObjectManager; /** * */ -class DataHandlerTest extends FunctionalTestCase +class DataHandlerTest extends AbstractFunctionalTestCase { public function setUp() { diff --git a/Tests/Functional/Indexing/IndexTcaTableTest.php b/Tests/Functional/Indexing/IndexTcaTableTest.php index fc2ce65..cbd195c 100644 --- a/Tests/Functional/Indexing/IndexTcaTableTest.php +++ b/Tests/Functional/Indexing/IndexTcaTableTest.php @@ -21,13 +21,13 @@ namespace Leonmrni\SearchCore\Tests\Functional\Indexing; */ use Leonmrni\SearchCore\Domain\Index\IndexerFactory; -use Leonmrni\SearchCore\Tests\Functional\FunctionalTestCase; +use Leonmrni\SearchCore\Tests\Functional\AbstractFunctionalTestCase; use TYPO3\CMS\Extbase\Object\ObjectManager; /** * */ -class IndexTcaTableTest extends FunctionalTestCase +class IndexTcaTableTest extends AbstractFunctionalTestCase { public function setUp() { From d4ccf6a7ea7debed20b321903eb7815a7820ed5d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 12 Dec 2016 18:04:50 +0100 Subject: [PATCH 12/14] Fix codacy issue --- Tests/Functional/Hooks/DataHandlerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index f64fbd6..a1a17b7 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -105,6 +105,7 @@ class DataHandlerTest extends AbstractFunctionalTestCase $hook = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Hook::class); $hook->processDatamap_afterDatabaseOperations('something', 'tt_content', 6, [], $dataHandler); - $response = $this->client->request('typo3content/_search?q=*:*'); + // Should trigger Exception + $this->client->request('typo3content/_search?q=*:*'); } } From dc8e04b4490695414b39e60dcd2983dc4b2e7f65 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 12 Dec 2016 21:18:22 +0100 Subject: [PATCH 13/14] CLEANUP: Remove debugging code --- Tests/Functional/AbstractFunctionalTestCase.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/Functional/AbstractFunctionalTestCase.php b/Tests/Functional/AbstractFunctionalTestCase.php index 743b4cc..fd90e8e 100644 --- a/Tests/Functional/AbstractFunctionalTestCase.php +++ b/Tests/Functional/AbstractFunctionalTestCase.php @@ -54,9 +54,7 @@ abstract class AbstractFunctionalTestCase extends CoreTestCase public function tearDown() { // Delete everything so next test starts clean. - if ($this->client) { $this->client->getIndex('_all')->delete(); $this->client->getIndex('_all')->clearCache(); - } } } From e1e867befdee5dfbbac042e0c311c1c9c5133bd5 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 12 Dec 2016 22:47:45 +0100 Subject: [PATCH 14/14] Feature/integrate codacy (#9) * REFACTOR: Move scripts to Makefile * FEATURE: Add codacy --- .travis.yml | 4 +--- Makefile | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 84984ad..539e746 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,9 +46,7 @@ install: make install script: make Tests after_script: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover .Build/report/unit/clover/coverage - - php ocular.phar code-coverage:upload --format=php-clover .Build/report/functional/clover/coverage + - make uploadCodeCoverage - make clean cache: diff --git a/Makefile b/Makefile index 7fe83d5..be9f02c 100644 --- a/Makefile +++ b/Makefile @@ -31,5 +31,18 @@ functionalTests: .PHONY: Tests Tests: unitTests functionalTests +uploadCodeCoverage: uploadCodeCoverageToScrutinizer uploadCodeCoverageToCodacy + +uploadCodeCoverageToScrutinizer: + wget https://scrutinizer-ci.com/ocular.phar && \ + php ocular.phar code-coverage:upload --format=php-clover .Build/report/unit/clover/coverage && \ + php ocular.phar code-coverage:upload --format=php-clover .Build/report/functional/clover/coverage + +uploadCodeCoverageToCodacy: + composer require -vv --dev codacy/coverage && \ + git checkout composer.json && \ + php .Build/bin/codacycoverage clover .Build/report/unit/clover/coverage && \ + php .Build/bin/codacycoverage clover .Build/report/functional/clover/coverage + clean: rm -rf .Build composer.lock