diff --git a/README.md b/README.md index 7c6967f..cb8894e 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ If you want to help check the contribuing instructions [here](CONTRIBUTING.md). ## TODO - [x] Bump the PHP minimum version to 5.4+ -- [ ] Create more unit tests +- [x] Create more unit tests - [ ] Rewrite html2pdf examples using `Zff\Html2Pdf` - [ ] Create a way to easily change params from HTML2PDF's constructor, called on `Html2PdfRenderer` class, on controller, view or config file. diff --git a/composer.json b/composer.json index 4cda0ed..18290d2 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,14 @@ "spipu/html2pdf":"~4.4" }, "require-dev": { - "zendframework/zendframework":"~2.4.0", + "zendframework/zend-servicemanager":"~2.4", + "zendframework/zend-modulemanager":"~2.4", + "zendframework/zend-mvc":"~2.4", + "zendframework/zend-filter":"~2.4", + "zendframework/zend-serializer":"~2.4", + "zendframework/zend-log":"~2.4", + "zendframework/zend-i18n":"~2.4", + "zendframework/zend-console":"~2.4", "phpunit/phpunit": "~4.0", "squizlabs/php_codesniffer": "~2", "thomasbachem/php-short-array-syntax-converter": "dev-master" diff --git a/phpunit.xml b/phpunit.xml index 739ec9c..e6d2243 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ diff --git a/test/Bootstrap.php b/test/Bootstrap.php deleted file mode 100644 index 62ce259..0000000 --- a/test/Bootstrap.php +++ /dev/null @@ -1,134 +0,0 @@ - [ - 'module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths), - ], - ]; - - $config = ArrayUtils::merge($baseConfig, $testConfig); - - $serviceManager = new ServiceManager(new ServiceManagerConfig()); - $serviceManager->setService('ApplicationConfig', $config); - $serviceManager->get('ModuleManager')->loadModules(); - - $application = new Application($config, $serviceManager); - $application->bootstrap(); - - static::$serviceManager = $serviceManager; - static::$config = $config; - } - - public static function getServiceManager() - { - return static::$serviceManager; - } - - public static function getConfig() - { - return static::$config; - } - - protected static function initAutoloader() - { - $vendorPath = static::findParentPath('vendor'); - - if (is_readable($vendorPath.'/autoload.php')) { - include $vendorPath.'/autoload.php'; - } else { - $zf2Path = getenv('ZF2_PATH') ? : (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath.'/ZF2/library') - ? $vendorPath.'/ZF2/library' : false)); - - if (!$zf2Path) { - throw new RuntimeException( - 'Unable to load ZF2. Run `php composer.phar ' - .'install` or define a ZF2_PATH environment variable.' - ); - } - - include $zf2Path.'/Zend/Loader/AutoloaderFactory.php'; - } - - AutoloaderFactory::factory([ - 'Zend\Loader\StandardAutoloader' => [ - 'autoregister_zf' => true, - 'namespaces' => [ - __NAMESPACE__ => __DIR__.'/'.__NAMESPACE__, - ], - ], - ]); - } - - protected static function findParentPath($path) - { - $dir = __DIR__; - $previousDir = '.'; - while (!is_dir($dir.'/'.$path)) { - $dir = dirname($dir); - if ($previousDir === $dir) { - return false; - } - $previousDir = $dir; - } - return $dir.'/'.$path; - } -} - -Bootstrap::init(); diff --git a/test/ModuleTest.php b/test/ModuleTest.php index 5a97627..5d5e6c7 100644 --- a/test/ModuleTest.php +++ b/test/ModuleTest.php @@ -7,6 +7,7 @@ namespace ZffTest\Html2Pdf; use PHPUnit_Framework_TestCase as TestCase; +use Zff\Html2Pdf\Module; /** * @author Vinicius Fagundes @@ -15,30 +16,25 @@ class ModuleTest extends TestCase { /** - * Scans service manager configuration, returning all services created by factories and invokables - * @return array + * @var Module */ - public function provideServiceList() + protected $module; + + public function setUp() { - return [ - [ - 'service' => 'ViewHtml2PdfStrategy', - 'class' => '\Zff\Html2Pdf\View\Strategy\Html2PdfStrategy' - ] - ]; + $this->module = new Module; } - /** - * @dataProvider provideServiceList - */ - public function testService($service, $class) + public function testConfig() { - $sm = Bootstrap::getServiceManager(); + $this->assertNotEmpty($this->module->getConfig()); - // test if service is available in SM - $this->assertTrue($sm->has($service)); + $configArr = include __DIR__.'/../config/module.config.php'; + + $this->assertEquals($configArr, $this->module->getConfig()); + } - // test if correct instance is created - $this->assertInstanceOf($class, $sm->get($service)); + public function testAutoloader() { + $this->assertNotEmpty($this->module->getAutoloaderConfig()); } } \ No newline at end of file diff --git a/test/Mvc/Service/ViewHtml2PdfStrategyFactoryTest.php b/test/Mvc/Service/ViewHtml2PdfStrategyFactoryTest.php new file mode 100644 index 0000000..5f89228 --- /dev/null +++ b/test/Mvc/Service/ViewHtml2PdfStrategyFactoryTest.php @@ -0,0 +1,46 @@ + ['Zff\\Html2Pdf'], 'module_listener_options' => []]; + + $serviceManager = new ServiceManager(new ServiceManagerConfig()); + $serviceManager->setService('ApplicationConfig', $config); + $serviceManager->get('ModuleManager')->loadModules(); + + $application = new Application($config, $serviceManager); + $application->bootstrap(); + + $this->serviceManager = $serviceManager; + } + + public function testCanCreateHtml2PdfStrategyFromNewFactoryInstance() + { + $factory = new ViewHtml2PdfStrategyFactory; + $this->assertInstanceOf('\Zff\Html2Pdf\View\Strategy\Html2PdfStrategy', $factory->createService($this->serviceManager)); + } + + public function testCanCreateHtml2PdfStrategyFromServiceManager() + { + $this->assertInstanceOf('\Zff\Html2Pdf\View\Strategy\Html2PdfStrategy', $this->serviceManager->get('ViewHtml2PdfStrategy')); + } +} \ No newline at end of file diff --git a/test/TestConfig.php b/test/TestConfig.php deleted file mode 100644 index a5b228f..0000000 --- a/test/TestConfig.php +++ /dev/null @@ -1,19 +0,0 @@ - [ - 'Zff\\Html2Pdf', - ], - 'module_listener_options' => [ - 'config_glob_paths' => [ - ], - 'module_paths' => [ - 'module', - 'vendor', - ], - ], -];