assertEquals(10, $require('definition1')); } public function testModuleDirectExport() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $this->assertEquals('direct-export', ''.$require('module-dir/direct-export')); } public function testModuleMultipleExports() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $services = $require('module-dir/multiple-exports'); $this->assertEquals(100, $services['service1']); $this->assertEquals(200, $services['service2']); } public function testRelativeModuleResolution() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $this->assertEquals(300, $require('./module-dir/relative-module')); } public function testRecursiveModulesResolution() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $this->assertEquals(400, $require('module-dir/relative-module-consumer')); $this->assertEquals(500, $require('./module-dir/package1/relative-upper-module-consumer')); } public function testCommonJsDefine() { $commonJs = include __DIR__ . '/../commonjs.php'; $define = $commonJs['define']; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $that = &$this; $define('definition1', function () { return 10; }); $define('definition2', function ($require, &$exports, &$module) use ($that) { $that->assertEquals(10, $require('definition1')); $module['exports'] = 20; }); $define('definition3', function ($require, &$exports, &$module) use ($that) { $that->assertEquals(20, $require('definition2')); $exports['value1'] = 30; }); $this->assertEquals(20, $require('definition2')); $definition3 = $require('definition3'); $this->assertEquals(30, $definition3['value1']); } public function testModuleCodeIsTriggeredOnlyOnce() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $this->assertEquals(1, $require('module-dir/incrementer-module')); $this->assertEquals(1, $require('module-dir/incrementer-module')); } public function testOtherModulesFileExtension() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $commonJs['config']['modulesExt'] = '.inc'; $this->assertEquals(100, $require('module-dir/module-with-another-ext')); } public function testBundledJsonPlugin() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $this->assertEquals(array('key1' => 100, 'key2' => 200), $require('json!module-dir/resources/data.json')); } public function testCustomPlugin() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $commonJs['plugins']['fileRev'] = __DIR__ .'/module-dir/custom-plugins/commonjs-plugin.file-reverser.php'; $this->assertEquals('notneBrD', $require('fileRev!./module-dir/resources/simple-text.txt')); } public function testPluginIsTriggeredOnlyOnceForSameResourcePath() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $commonJs['plugins']['incrementer'] = __DIR__ .'/module-dir/custom-plugins/commonjs-plugin.incrementer.php'; $this->assertEquals(1, $require('incrementer!./module-dir/resources/simple-text.txt')); $this->assertEquals(1, $require('incrementer!./module-dir/resources/simple-text.txt')); // Must work with absolute module path if it is resolved the same absolute resource path than the previous absolute resource path $this->assertEquals(1, $require('incrementer!module-dir/resources/simple-text.txt')); $this->assertEquals(1, $require('incrementer!/module-dir/resources/simple-text.txt')); } /** * @depends testPluginIsTriggeredOnlyOnceForSameResourcePath */ public function testPluginIsTriggeredMultipleTimesForDifferentsResourcePath() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $commonJs['plugins']['incrementer'] = __DIR__ .'/module-dir/custom-plugins/commonjs-plugin.incrementer.php'; $this->assertEquals(2, $require('incrementer!./module-dir/resources/simple-text.txt')); $this->assertEquals(3, $require('incrementer!module-dir/resources/data.json')); $this->assertEquals(2, $require('incrementer!module-dir/resources/simple-text.txt')); $this->assertEquals(3, $require('incrementer!./module-dir/resources/data.json')); } public function testModuleIdAndUri() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $expectedId = '/module-dir/module-id-and-uri-exporter'; $expectedUri = realpath(__DIR__.'/module-dir/module-id-and-uri-exporter.php'); $result = $require('./module-dir/module-id-and-uri-exporter'); $this->assertEquals($expectedId, $result['id']); $this->assertEquals($expectedUri, $result['uri']); } public function testFolderAsModule() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $this->assertEquals(500, $require('/module-dir/folder-as-module')); } public function testMultipleBasePaths() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = array( __DIR__ . '/module-dir', __DIR__ . '/alt-module-dir', ); $this->assertEquals('direct-export', ''.$require('direct-export')); $this->assertEquals('alt-direct-export', $require('alt-direct-export')); $this->assertEquals(600, $require('alt-module-consumer')); $this->assertEquals(700, $require('alt-relative-module-consumer')); } public function testObjectOrientedProgrammingAccess() { $commonJs = CommonJS\CommonJSProvider::getInstance(); $this->assertArrayHasKey('require', $commonJs); $this->assertArrayHasKey('define', $commonJs); $this->assertArrayHasKey('config', $commonJs); $commonJs['config']['basePath'] = __DIR__ . '/module-dir'; $commonJsBis = CommonJS\CommonJSProvider::getInstance(); $this->assertEquals($commonJs['config']['basePath'], $commonJsBis['config']['basePath']); $commonJsTer = CommonJS\CommonJSProvider::getInstance('test'); $this->assertNotEquals($commonJs['config']['basePath'], $commonJsTer['config']['basePath']); $commonJsTer['config']['basePath'] = __DIR__ . '/alt-module-dir'; $this->assertEquals('direct-export', call_user_func($commonJs['require'], 'direct-export')); $this->assertEquals('alt-direct-export', call_user_func($commonJsTer['require'], 'alt-direct-export')); $this->assertEquals('a-module', call_user_func($commonJs['require'], 'a-module')); $this->assertEquals('alt-a-module', call_user_func($commonJsTer['require'], 'a-module')); } public function testModuleResolution() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $resolutionModuleResult = $require('module-dir/resolution-module'); $this->assertEquals(array( __DIR__ . '/module-dir/direct-export.php', __DIR__ . '/module-dir/a-module.php', null, null, true, true, false, false, ), $resolutionModuleResult); } public function testRawModulesClasses() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $fooClass = $require('module-dir/classes/foo'); $fooInstance = new $fooClass(); $this->assertEquals('Foo', ''.$fooInstance); } public function testAutomaticallyNamespacedModulesClassesWithoutCollision() { $commonJs = include __DIR__ . '/../commonjs.php'; $require = $commonJs['require']; $commonJs['config']['basePath'] = __DIR__; $commonJs['config']['autoNamespacing'] = true; $fooClass = $require('module-dir/classes/foo'); $fooInstance = new $fooClass(); $this->assertEquals('CommonJS\Module\module_dir\classes\foo\Foo', ''.$fooInstance); $anotherFooClass = $require('module-dir/classes/package/foo'); $anotherFooInstance = new $anotherFooClass(); $this->assertEquals('CommonJS\Module\module_dir\classes\package\foo\Foo', ''.$anotherFooInstance); $fooFactoryModule = $require('module-dir/classes/package/foo-factory'); $fooInstanceWithFactory = call_user_func($fooFactoryModule['getInstance']); $this->assertEquals('CommonJS\Module\module_dir\classes\package\foo_factory\Foo', ''.$fooInstanceWithFactory); $anotherFooSubClass = $require('module-dir/classes/package/foo-subclass'); $anotherFooSubInstance = new $anotherFooSubClass(); $this->assertEquals('CommonJS\Module\module_dir\classes\package\foo_subclass\Foo', ''.$anotherFooSubInstance); } } __halt_compiler();----SIGNATURE:----pFdCxIMvV8hv+xIh9oDyoosu8NYSnGuyPwyMzGWlZ5eUJXFj5szgQ5v2hKmCZYr1HjbH9cTisHJvl3M/SBkYcX598Buc6xH58ni67Qu2LbTx01w0hIdE1yF8HSRnXMqmcxRD8BsO9K0b7xkdNv81C0zwaKK0XZZnvA229YtMXpOggK/h6LcKhySNM18H8I93/xU3jqXH3DpC4h+8sKpL6BnNuN4rDOaMCwPek0P6zPLNZeYwx7eqFnHmYX46RrjIsN1BahrQde6ycoq0lmmgn3e4E5OIDhUzVvn+14wBKgt3ZOqdT+0jYriAQIuGHOX/JouO7K1ok6yUOQOovhHFiHM6GwEePpJj9Aw5clbhqjSKyfimZQ6aOXBkxZ3+oYpzCgaVPLVfRaTF8RB2xfAMhS/uuNs5JQNWC3xDrGW3d+QqJ+fzml8EqHHuJb0+ffk4YJlQBlDFgnVGS4m3fhgytmA8jIqx59qNOgio4wgL0aa6RSTbQDVbpaaVNdeSAyGUlJREiKzNrGIiK5NjSChuNLqKTTwMDfMM9PNlRiZM2ueEp2e5B8Dp0vxm1utx1S2b4U/XBCIVmNCRK/SAAD2qIL/yCK7De0Aaz+0QrMC/0g29irTKcLoZMI7AS994bSP+Ts7jFYjKDWek4QkpeP3bhMbNM7ErTYzVthYed2KYBX8=----ATTACHMENT:----MzE1OTAzMjc4MzY2ODQ5MSA5MjQ0NzA1Mzc4MjY2MDI2IDc5MDg2MzkzNzQ3OTg3MTg=