Merge pull request #7 from DanielSiepmann/feature/add-functional-tests

Feature/add functional tests
This commit is contained in:
Daniel Siepmann 2016-12-13 09:20:39 +01:00 committed by GitHub
commit e30463ddc7
19 changed files with 594 additions and 135 deletions

View file

@ -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

View file

@ -3,8 +3,18 @@ language: php
php:
- 5.6
- 7.0
- 7.1
env:
global:
- TYPO3_DATABASE_NAME="typo3_ci"
- TYPO3_DATABASE_HOST="127.0.0.1"
- 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"
@ -12,25 +22,32 @@ 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
before_install:
- composer self-update
- composer --version
services:
- mysql
- elasticsearch
install:
- make install
install: make install
script:
- make Tests
script: make Tests
after_script:
- make uploadCodeCoverage
- make clean
cache:
directories:

View file

@ -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($type->getName(), $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 ($document) {
$type->updateDocument($this->documentFactory->getDocument($type->getName(), $document));
}
);
}
/**
@ -103,24 +118,30 @@ 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($type->getName(), $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();
}
/**
* @param SearchRequestInterface $searchRequest
* @return SearchResultInterface
* @return \Elastica\ResultSet
*/
public function search(SearchRequestInterface $searchRequest)
{
@ -130,6 +151,23 @@ 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());
}
/**
* @param string $documentType
*
* @return \Elastica\Type
*/
protected function getType($documentType)
{
return $this->typeFactory->getType(
$this->indexFactory->getIndex(
$this->connection,
$documentType
),
$documentType
);
}
}

View file

@ -31,4 +31,11 @@ interface IndexerInterface
* @return void
*/
public function index();
/**
* Index a single record.
*
* @return void
*/
public function indexRecord($identifier);
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -74,15 +74,18 @@ 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);
return true;
}
/**
@ -93,18 +96,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,13 +117,14 @@ class DataHandler implements Singleton
if ($record !== null) {
$this->dataHandler->update($table, $record);
}
return;
return false;
}
$this->logger->debug(
'Database update not processed, cause status is unhandled.',
[$status, $table, $uid, $fieldArray]
);
return true;
}
/**
@ -149,7 +155,7 @@ class DataHandler implements Singleton
*
* @param string $table
* @param int $uid
* @return null|array
* @return null|array<String>
*/
protected function getRecord($table, $uid)
{

View file

@ -1,80 +0,0 @@
<?php
namespace Leonmrni\SearchCore\Service;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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);
}
}

View file

@ -3,18 +3,46 @@ 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
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) \
.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
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

View file

@ -0,0 +1,60 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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 AbstractFunctionalTestCase extends CoreTestCase
{
protected $testExtensionsToLoad = ['typo3conf/ext/search_core'];
/**
* @var \Elastica\Client
*/
protected $client;
public function setUp()
{
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,
'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();
}
}

View file

@ -0,0 +1,12 @@
plugin {
tx_searchcore {
settings {
connection {
host = localhost
port = 9200
}
}
}
}
module.tx_searchcore < plugin.tx_searchcore

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<pages>
<uid>1</uid>
<pid>0</pid>
<title>Root page containing necessary TypoScript</title>
</pages>
</dataset>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<tt_content>
<uid>6</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>textmedia</CType>
<header>test</header>
<bodytext>this is the content of textmedia content element that should get indexed</bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>
<cols>0</cols>
<starttime>0</starttime>
<endtime>0</endtime>
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
</dataset>

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<tt_content>
<uid>6</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>textmedia</CType>
<header>test</header>
<bodytext>this is the content of textmedia content element that should get indexed</bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>
<cols>0</cols>
<starttime>0</starttime>
<endtime>0</endtime>
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
<tt_content>
<uid>7</uid>
<pid>1</pid>
<tstamp>1480686371</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>textmedia</CType>
<header>endtime hidden record</header>
<bodytext></bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>
<cols>0</cols>
<starttime>0</starttime>
<endtime>1481305963</endtime>
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
<tt_content>
<uid>8</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>1</hidden>
<sorting>72</sorting>
<CType>textmedia</CType>
<header>Hidden record</header>
<bodytext></bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>
<cols>0</cols>
<starttime>0</starttime>
<endtime>0</endtime>
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
</dataset>

View file

@ -0,0 +1,34 @@
<phpunit
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="../../.Build/vendor/typo3/cms/typo3/sysext/core/Build/FunctionalTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="false"
convertWarningsToExceptions="false"
forceCoversAnnotation="false"
processIsolation="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false">
<testsuites>
<testsuite name="functional-tests">
<directory>.</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">../../Classes</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="../../.Build/report/functional/html" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="../../.Build/report/functional/clover/coverage"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
</logging>
</phpunit>

View file

@ -0,0 +1,111 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Hooks;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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\AbstractFunctionalTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
*
*/
class DataHandlerTest extends AbstractFunctionalTestCase
{
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);
// Should trigger Exception
$this->client->request('typo3content/_search?q=*:*');
}
}

View file

@ -0,0 +1,88 @@
<?php
namespace Leonmrni\SearchCore\Tests\Functional\Indexing;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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\AbstractFunctionalTestCase;
use TYPO3\CMS\Extbase\Object\ObjectManager;
/**
*
*/
class IndexTcaTableTest extends AbstractFunctionalTestCase
{
public function setUp()
{
parent::setUp();
$this->importDataSet('Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml');
}
/**
* @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.');
}
/**
* @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')
;
}
/**
* @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.');
}
}

View file

@ -19,4 +19,16 @@
<directory>.</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">../../Classes</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="../../.Build/report/unit/html" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-clover" target="../../.Build/report/unit/clover/coverage"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
</logging>
</phpunit>

View file

@ -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"