From e41c14cb75bac9816fe158908bd5ee364b35bd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr> Date: Tue, 3 May 2016 12:51:52 +0000 Subject: [PATCH] Initialisation du module --- Module.php | 28 ++++++++ autoload_classmap.php | 5 ++ composer.json | 26 +++++++ config/module.config.php | 6 ++ config/unicaen-import.global.php.dist | 4 ++ nbproject/project.properties | 7 ++ nbproject/project.xml | 9 +++ tests/Bootstrap.php | 97 +++++++++++++++++++++++++++ tests/config/application.config.php | 18 +++++ tests/config/autoload/global.php | 2 + tests/phpunit.xml | 24 +++++++ 11 files changed, 226 insertions(+) create mode 100644 Module.php create mode 100644 autoload_classmap.php create mode 100644 composer.json create mode 100644 config/module.config.php create mode 100644 config/unicaen-import.global.php.dist create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 tests/Bootstrap.php create mode 100644 tests/config/application.config.php create mode 100644 tests/config/autoload/global.php create mode 100644 tests/phpunit.xml diff --git a/Module.php b/Module.php new file mode 100644 index 0000000..4afc351 --- /dev/null +++ b/Module.php @@ -0,0 +1,28 @@ +<?php + +namespace UnicaenImport; + +use Zend\ModuleManager\Feature\ConfigProviderInterface; +use Zend\Mvc\MvcEvent; + +include_once 'Functions.php'; + +/** + * + * + * @author Laurent LECLUSE <laurent.lecluse at unicaen.fr> + */ +class Module implements ConfigProviderInterface +{ + public function onBootstrap(MvcEvent $e) + { + + } + + + + public function getConfig() + { + return include __DIR__ . '/config/module.config.php'; + } +} diff --git a/autoload_classmap.php b/autoload_classmap.php new file mode 100644 index 0000000..3589273 --- /dev/null +++ b/autoload_classmap.php @@ -0,0 +1,5 @@ +<?php +// Generated by ZF2's ./bin/classmap_generator.php +return array( + 'UnicaenImport\Module' => __DIR__ . '/Module.php', +); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..08c0ad5 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name" : "unicaen/unicaen-import", + "description" : "Boite à outils pour la programmation avec la bibliothèque Unicaen", + "repositories": [ + { + "type": "composer", + "url" : "http://dev.unicaen.fr/packagist" + } + ], + "require" : { + + }, + "require-dev" : { + "phpunit/PHPUnit" : ">=3.7", + + }, + "autoload" : { + "psr-0" : { + "UnicaenImport" : "src/", + "UnicaenImportTest": "tests/" + }, + "classmap": [ + "./Module.php" + ] + } +} diff --git a/config/module.config.php b/config/module.config.php new file mode 100644 index 0000000..8cbd0ff --- /dev/null +++ b/config/module.config.php @@ -0,0 +1,6 @@ +<?php + +return [ + 'unicaen-import' => [ + ] +]; diff --git a/config/unicaen-import.global.php.dist b/config/unicaen-import.global.php.dist new file mode 100644 index 0000000..b625128 --- /dev/null +++ b/config/unicaen-import.global.php.dist @@ -0,0 +1,4 @@ +<?php + +return [ +]; diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..76f6f91 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_56 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..a93bd6c --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.php.project</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/php-project/1"> + <name>unicaen-import</name> + </data> + </configuration> +</project> diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php new file mode 100644 index 0000000..cecb196 --- /dev/null +++ b/tests/Bootstrap.php @@ -0,0 +1,97 @@ +<?php +namespace UnicaenImportTest; + +use Zend\Loader\AutoloaderFactory; +use Zend\Mvc\Service\ServiceManagerConfig; +use Zend\ServiceManager\ServiceManager; +use RuntimeException; + + +error_reporting(E_ALL | E_STRICT); +chdir(__DIR__); + +/** + * Test bootstrap, for setting up autoloading + */ +class Bootstrap +{ + /** + * + * @var ServiceManager + */ + protected static $serviceManager; + + public static function init() + { + $zf2ModulePaths = array(dirname(dirname(__DIR__))); + if (($path = static::findParentPath('vendor'))) { + $zf2ModulePaths[] = $path; + } + if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) { + $zf2ModulePaths[] = $path; + } + $zf2ModulePaths[] = __DIR__; + + static::initAutoloader(); + + // use ModuleManager to load this module and it's dependencies + $serviceManager = new ServiceManager(new ServiceManagerConfig()); + $serviceManager->setService('ApplicationConfig', require_once './config/application.config.php'); + $serviceManager->get('ModuleManager')->loadModules(); + static::$serviceManager = $serviceManager; + } + + public static function getServiceManager() + { + return static::$serviceManager; + } + + protected static function initAutoloader() + { + $vendorPath = static::findParentPath('vendor'); + + if (is_readable($vendorPath . '/autoload.php')) { + include $vendorPath . '/autoload.php'; + return; + } + + $zf2Path = getenv('ZF2_PATH'); + if (!$zf2Path) { + if (defined('ZF2_PATH')) { + $zf2Path = ZF2_PATH; + } elseif (is_dir($vendorPath . '/ZF2/library')) { + $zf2Path = $vendorPath . '/ZF2/library'; + } elseif (is_dir($vendorPath . '/zendframework/zendframework/library')) { + $zf2Path = $vendorPath . '/zendframework/zendframework/library'; + } + } + + 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(array( + 'Zend\Loader\StandardAutoloader' => array( + 'autoregister_zf' => true, + 'namespaces' => array( + __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/tests/config/application.config.php b/tests/config/application.config.php new file mode 100644 index 0000000..3a3d385 --- /dev/null +++ b/tests/config/application.config.php @@ -0,0 +1,18 @@ +<?php + +// Application config +$appConfig = array();//include __DIR__ . '/../../../../../config/application.config.php'; + +// Test config +$testConfig = array( + 'modules' => array( + 'UnicaenImport' + ), + 'module_listener_options' => array( + 'config_glob_paths' => array( + __DIR__ . '/autoload/{,*.}{global,local}.php', + ), + ), +); + +return \Zend\Stdlib\ArrayUtils::merge($appConfig, $testConfig); diff --git a/tests/config/autoload/global.php b/tests/config/autoload/global.php new file mode 100644 index 0000000..881ab67 --- /dev/null +++ b/tests/config/autoload/global.php @@ -0,0 +1,2 @@ +<?php +return []; diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..59dc2ca --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit bootstrap="./Bootstrap.php" colors="true"> + <testsuites> + <testsuite name="UnicaenImport"> + <directory>./UnicaenImportTest</directory> + </testsuite> + </testsuites> + + <logging> + <!--<log type="junit" target="/tmp/phpunit/logs/junit.xml" />--> + <!--<log type="coverage-clover" target="/tmp/phpunit/logs/clover.xml" />--> + <!--<log type="coverage-html" target="/tmp/phpunit/coverage" />--> + </logging> + + <filter> + <whitelist processUncoveredFilesFromWhitelist="true"> + <directory suffix=".php">../src</directory> + </whitelist> + </filter> + + <groups> + </groups> +</phpunit> -- GitLab