diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..9f726bc --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,2 @@ +service_name: travis-pro +repo_token: 2VO5MRpRQxkxYiQnbJF064rTEZIJ1AbVW \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8925195 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +vendor +composer.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d8cd57f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: php +php: + - '5.6' + - '7.0' +install: + - composer install +script: + - mkdir -p build/logs + - php vendor/bin/phpunit +after_success: + - travis_retry php vendor/bin/coveralls -v \ No newline at end of file diff --git a/Module.php b/Module.php index 41239b8..7bd5c2b 100644 --- a/Module.php +++ b/Module.php @@ -1,6 +1,6 @@ setCurrentPageNumber($page); $paginator->setItemCountPerPage($countPerPage); diff --git a/autoload_classmap.php b/autoload_classmap.php new file mode 100644 index 0000000..881ab67 --- /dev/null +++ b/autoload_classmap.php @@ -0,0 +1,2 @@ + array( 'factories' => array( - 'Solarium\Client' => 'EwgoSolarium\Service\SolariumFactory', - 'EwgoSolarium\Collector\RequestCollector' => 'EwgoSolarium\Service\RequestCollectorFactory', - 'EwgoSolarium\Plugin\RequestLogger' => 'EwgoSolarium\Service\RequestLoggerFactory' + 'Solarium\Client' => SynergySolarium\Service\SolariumFactory::class, + 'SynergySolarium\Collector\RequestCollector' => SynergySolarium\Service\RequestCollectorFactory::class, + 'SynergySolarium\Plugin\RequestLogger' => SynergySolarium\Service\RequestLoggerFactory::class ), 'aliases' => array( - 'solarium' => 'Solarium\Client', - 'solarium.collector' => 'EwgoSolarium\Collector\RequestCollector', - 'solarium.logger' => 'EwgoSolarium\Plugin\RequestLogger' + 'solarium' => Solarium\Client::class, + 'solarium.collector' => SynergySolarium\Collector\RequestCollector::class, + 'solarium.logger' => SynergySolarium\Plugin\RequestLogger::class ) ), @@ -23,12 +23,12 @@ 'zenddevelopertools' => array( 'profiler' => array( 'collectors' => array( - 'solarium' => 'solarium.collector', + 'solarium' => 'solarium.collector', ), ), 'toolbar' => array( 'entries' => array( - 'solarium' => 'zend-developer-tools/toolbar/solarium-requests', + 'solarium' => 'zend-developer-tools/toolbar/solarium-requests', ), ), ), diff --git a/init_autoloader.php b/init_autoloader.php new file mode 100755 index 0000000..2967224 --- /dev/null +++ b/init_autoloader.php @@ -0,0 +1,47 @@ +add('Zend', $zf2Path . '/Zend'); + } else { + include $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; + Zend\Loader\AutoloaderFactory::factory( + array( + 'Zend\Loader\StandardAutoloader' => array( + 'autoregister_zf' => true + ) + ) + ); + } +} + +if ( ! class_exists('Zend\Loader\AutoloaderFactory')) { + throw new RuntimeException( + 'Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.' + ); +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100755 index 0000000..999b093 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,19 @@ + + + + + + tests + + + + tests + ../../vendor + ../../src + + + + src + + + \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100755 index 0000000..999b093 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + + + tests + + + + tests + ../../vendor + ../../src + + + + src + + + \ No newline at end of file diff --git a/src/EwgoSolarium/Service/RequestCollectorFactory.php b/src/EwgoSolarium/Service/RequestCollectorFactory.php deleted file mode 100644 index a52f4b3..0000000 --- a/src/EwgoSolarium/Service/RequestCollectorFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -get('solarium.logger')); - } -} diff --git a/src/EwgoSolarium/Service/RequestLoggerFactory.php b/src/EwgoSolarium/Service/RequestLoggerFactory.php deleted file mode 100644 index 8a952af..0000000 --- a/src/EwgoSolarium/Service/RequestLoggerFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -register($serviceLocator->get('solarium')); - return $logger; - } -} diff --git a/src/EwgoSolarium/Service/SolariumFactory.php b/src/EwgoSolarium/Service/SolariumFactory.php deleted file mode 100644 index c11851f..0000000 --- a/src/EwgoSolarium/Service/SolariumFactory.php +++ /dev/null @@ -1,30 +0,0 @@ -get('Configuration'); - $client = new Client(isset($config['solarium']) ? $config['solarium'] : array()); - - return $client; - } -} diff --git a/src/EwgoSolarium/Collector/RequestCollector.php b/src/SynergySolarium/Collector/RequestCollector.php similarity index 93% rename from src/EwgoSolarium/Collector/RequestCollector.php rename to src/SynergySolarium/Collector/RequestCollector.php index b17845c..c6518ab 100644 --- a/src/EwgoSolarium/Collector/RequestCollector.php +++ b/src/SynergySolarium/Collector/RequestCollector.php @@ -1,17 +1,17 @@ get('solarium.logger')); + } +} diff --git a/src/SynergySolarium/Service/RequestLoggerFactory.php b/src/SynergySolarium/Service/RequestLoggerFactory.php new file mode 100644 index 0000000..166634a --- /dev/null +++ b/src/SynergySolarium/Service/RequestLoggerFactory.php @@ -0,0 +1,30 @@ +register($serviceLocator->get('solarium')); + return $logger; + } +} diff --git a/src/SynergySolarium/Service/SolariumFactory.php b/src/SynergySolarium/Service/SolariumFactory.php new file mode 100644 index 0000000..3c53121 --- /dev/null +++ b/src/SynergySolarium/Service/SolariumFactory.php @@ -0,0 +1,31 @@ +get('Configuration'); + $client = new Client(isset($config['solarium']) ? $config['solarium'] : array()); + + return $client; + } +} diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php new file mode 100755 index 0000000..dde5a6f --- /dev/null +++ b/tests/Bootstrap.php @@ -0,0 +1,114 @@ + [ + 'Zend\Router', + 'SynergySolarium', + 'SynergySolariumTest' + ], + + 'module_listener_options' => array( + 'module_paths' => array( + './src', + './vendor', + ), + 'config_glob_paths' => array( + 'config/{,*.}{global,test,local}.php', + ), + 'config_cache_enabled' => false, + 'module_map_cache_enabled' => false, + 'cache_dir' => 'data/cache', + ), + ]; + + + include __DIR__ . '/../init_autoloader.php'; + + /** @var \Zend\Mvc\Application $app */ + $app = Application::init($config); + $serviceManager = $app->getServiceManager(); + $serviceManager->setAllowOverride(true); + static::$serviceManager = $serviceManager; + + } + + public static function getServiceManager() + { + return static::$serviceManager; + } + + /** + * + * @param string $path + * + * @return boolean|string false if the path cannot be found + */ + protected static function findParentPath($path) + { + $dir = __DIR__; + $srcDir = realpath($dir . '/../../'); + + return $srcDir . '/' . $path; + } +} + +Bootstrap::init(); diff --git a/tests/SynergySolariumTest/Collector/RequestCollectorTest.php b/tests/SynergySolariumTest/Collector/RequestCollectorTest.php new file mode 100644 index 0000000..6ca8a12 --- /dev/null +++ b/tests/SynergySolariumTest/Collector/RequestCollectorTest.php @@ -0,0 +1,22 @@ +serviceManager = Bootstrap::getServicemanager(); + } + + public function testCollectorInstance() + { + $instance = $this->serviceManager->get('solarium.collector'); + $this->assertInstanceOf(RequestCollector::class, $instance); + } +} \ No newline at end of file diff --git a/tests/SynergySolariumTest/Module.php b/tests/SynergySolariumTest/Module.php new file mode 100755 index 0000000..f6b33fc --- /dev/null +++ b/tests/SynergySolariumTest/Module.php @@ -0,0 +1,37 @@ +getApplication()->getEventManager(); + $moduleRouteListener = new ModuleRouteListener(); + $moduleRouteListener->attach($eventManager); + } + + public function getConfig() + { + return []; + } + + public function getAutoloaderConfig() + { + return array( + 'Zend\Loader\StandardAutoloader' => array( + 'namespaces' => array( + __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, + ), + ), + ); + } +} diff --git a/tests/SynergySolariumTest/Plugin/RequestLoggerTest.php b/tests/SynergySolariumTest/Plugin/RequestLoggerTest.php new file mode 100644 index 0000000..2664a96 --- /dev/null +++ b/tests/SynergySolariumTest/Plugin/RequestLoggerTest.php @@ -0,0 +1,22 @@ +serviceManager = Bootstrap::getServicemanager(); + } + + public function testRequestLoggerInstance() + { + $instance = $this->serviceManager->get('solarium.logger'); + $this->assertInstanceOf(RequestLogger::class, $instance); + } +} diff --git a/tests/SynergySolariumTest/Service/SolariumTest.php b/tests/SynergySolariumTest/Service/SolariumTest.php new file mode 100644 index 0000000..5898048 --- /dev/null +++ b/tests/SynergySolariumTest/Service/SolariumTest.php @@ -0,0 +1,44 @@ +serviceManager = Bootstrap::getServicemanager(); + } + + public function testSolariumClientInstance() + { + $instance = $this->serviceManager->get('solarium'); + $this->assertInstanceOf(Client::class, $instance); + } + + public function testPaginatorAdapter() + { + + $client = $this->prophesize(Client::class); + $query = $this->prophesize(Query::class); + $result = $this->prophesize(Result::class); + + + $client->select($query)->willREturn($result); + $adapter = new SolariumPaginator($client->reveal(), $query->reveal()); + + $this->assertNull($adapter->count()); + $this->assertInstanceOf(Result::class, $adapter->getItems(0, 10)); + + $result->getNumFound()->willReturn(3); + $this->assertSame(3, $adapter->count()); + } +} diff --git a/view/zend-developer-tools/toolbar/solarium-requests.phtml b/view/zend-developer-tools/toolbar/solarium-requests.phtml index 7b19889..d7b2f39 100644 --- a/view/zend-developer-tools/toolbar/solarium-requests.phtml +++ b/view/zend-developer-tools/toolbar/solarium-requests.phtml @@ -1,11 +1,11 @@ - +
Solarium (Requests) getRequestCount(); ?> queries in - zendDeveloperToolsTime($collector->getRequestTime()); ?> + ZendDeveloperToolsTime($collector->getRequestTime()); ?>
@@ -33,7 +33,7 @@ Time - zendDeveloperToolsTime($request['duration']) ?> + ZendDeveloperToolsTime($request['duration']) ?>