Example #1
0
 def _defaults(self):
     pkgdownloads = PKGDOWNLOADS
     pkgdownloads['COMPILATION_DIR'] = os.path.join(self._ctx['BUILD_DIR'], '.build_ibmdb_extension')
     pkgdownloads['DOWNLOAD_DIR'] = os.path.join('{COMPILATION_DIR}', '.downloads')        
     pkgdownloads['IBMDBCLIDRIVER_INSTALL_DIR'] = os.path.join(self._ctx['BUILD_DIR'], 'ibmdb_clidriver')
     pkgdownloads['PHPSOURCE_INSTALL_DIR'] = os.path.join('{COMPILATION_DIR}', 'php')
     pkgdownloads['IBM_DB2_DLDIR'] = os.path.join('{PHPSOURCE_INSTALL_DIR}', 'ext', 'ibm_db2')
     pkgdownloads['PDO_IBM_DLDIR'] = os.path.join('{PHPSOURCE_INSTALL_DIR}', 'ext', 'pdo_ibm')
     return utils.FormattedDict(pkgdownloads)
Example #2
0
 def test_ld_library_path_for_hhvm(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': '/usr/awesome/',
         'WEBDIR': '',
         'PHP_VM': 'hhvm'
     })
     stg = self.extension_module.HHVMComposerStrategy(ctx)
     path = stg.ld_library_path()
     eq_('/usr/awesome/hhvm/usr/lib/hhvm', path)
 def test_setup_if_htdocs_with_stand_alone_app(self):
     shutil.copytree('tests/data/app-5', self.build_dir)
     setup_webdir_if_it_doesnt_exist(
         utils.FormattedDict({
             'BUILD_DIR': self.build_dir,
             'WEB_SERVER': 'none'
         }))
     self.assert_exists(self.build_dir, 'app.php')
     eq_(1, len(os.listdir(self.build_dir)))
Example #4
0
 def test_ld_library_path_for_php(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': '/usr/awesome',
         'WEBDIR': '',
         'PHP_VM': 'php'
     })
     stg = self.extension_module.PHPComposerStrategy(ctx)
     path = stg.ld_library_path()
     eq_('/usr/awesome/php/lib', path)
Example #5
0
 def test_configure_composer_with_hhvm_version(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': 'tests/data/composer-with-hhvm',
         'HHVM_VERSION': '3.2.0'
     })
     config = self.extension_module.ComposerConfiguration(ctx)
     config.configure()
     assert '3.2.0' == ctx['HHVM_VERSION']
     assert 'hhvm' == ctx['PHP_VM']
Example #6
0
    def test_configure_paths_missing(self):
        fcp_orig = self.extension_module.find_composer_path

        def find_composer_path_none_found_stub(path, ctx):
            return None

        def find_composer_path_only_json_found_stub(path, ctx):
            if path == "composer.json":
                return fcp_orig(path, ctx)
            return None

        def find_composer_path_only_lock_found_stub(path, ctx):
            if path == "composer.lock":
                return fcp_orig(path, ctx)
            return None

        ctx = utils.FormattedDict({
            'BUILD_DIR': 'tests/data/composer',
            'WEBDIR': '',
            'PHP_71_LATEST': '7.1.4',
            'PHP_DEFAULT': '7.1.3',
            'ALL_PHP_VERSIONS': ['7.1.3', '7.1.4']
        })

        # test when no composer.json and no composer.lock found
        self.extension_module.find_composer_path = find_composer_path_none_found_stub
        try:
            self.extension_module.ComposerConfiguration(ctx).configure()
            assert 'PHP_EXTENSIONS' not in ctx.keys()
        finally:
            self.extension_module.find_composer_path = fcp_orig

        # test when composer.json found, but no composer.lock
        self.extension_module.find_composer_path = find_composer_path_only_json_found_stub
        try:
            self.extension_module.ComposerConfiguration(ctx).configure()
            assert 'PHP_EXTENSIONS' in ctx.keys()
            assert 3 == len(ctx['PHP_EXTENSIONS'])
            assert 'openssl' in ctx['PHP_EXTENSIONS']
            assert 'fileinfo' in ctx['PHP_EXTENSIONS']
            assert 'zip' in ctx['PHP_EXTENSIONS']
        finally:
            self.extension_module.find_composer_path = fcp_orig

        # test when composer.lock found, but no composer.json
        self.extension_module.find_composer_path = find_composer_path_only_lock_found_stub
        try:
            self.extension_module.ComposerConfiguration(ctx).configure()
            assert 'PHP_EXTENSIONS' in ctx.keys()
            assert 4 == len(ctx['PHP_EXTENSIONS'])
            assert 'openssl' in ctx['PHP_EXTENSIONS']
            assert 'gd' in ctx['PHP_EXTENSIONS']
            assert 'fileinfo' in ctx['PHP_EXTENSIONS']
            assert 'zip' in ctx['PHP_EXTENSIONS']
        finally:
            self.extension_module.find_composer_path = fcp_orig
Example #7
0
 def testDefaults(self):
     nr = newrelic.NewRelicInstaller(utils.FormattedDict({
         'BUILD_DIR': self.build_dir
     }))
     eq_(True, 'NEWRELIC_HOST' in nr._ctx.keys())
     eq_(True, 'NEWRELIC_VERSION' in nr._ctx.keys())
     eq_(True, 'NEWRELIC_PACKAGE' in nr._ctx.keys())
     eq_(True, 'NEWRELIC_DOWNLOAD_URL' in nr._ctx.keys())
     eq_(True, 'NEWRELIC_HASH_DOWNLOAD_URL' in nr._ctx.keys())
     eq_(True, 'NEWRELIC_STRIP' in nr._ctx.keys())
Example #8
0
 def test_composer_tool_should_compile_not_found(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': 'lib',
         'CACHE_DIR': '/cache/dir',
         'PHP_VM': 'will_default_to_php_strategy',
         'WEBDIR': 'htdocs',
         'LIBDIR': 'lib'
     })
     ct = self.extension_module.ComposerExtension(ctx)
     assert not ct._should_compile()
Example #9
0
 def test_composer_tool_uses_default_version_for(self):
     ctx = utils.FormattedDict({
         'BP_DIR': os.path.join(self.buildpack_dir, 'tests/data/composer-default-versions/'),
         'PHP_VM': 'will_default_to_php_strategy',
         'BUILD_DIR': '/build/dir',
         'CACHE_DIR': '/cache/dir',
         'WEBDIR': ''
     })
     ct = self.extension_module.ComposerExtension(ctx)
     assert ct._ctx['COMPOSER_VERSION'] == '9.9.9'
Example #10
0
 def test_composer_defaults(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': '/tmp/build',
         'CACHE_DIR': '/tmp/cache',
         'LIBDIR': 'lib'
     })
     builder = Dingus(_ctx=ctx)
     ct = self.ct.ComposerTool(builder)
     eq_('/tmp/build/lib/vendor', ct._ctx['COMPOSER_VENDOR_DIR'])
     eq_('/tmp/build/php/bin', ct._ctx['COMPOSER_BIN_DIR'])
     eq_('/tmp/cache/composer', ct._ctx['COMPOSER_CACHE_DIR'])
Example #11
0
 def test_composer_tool_detect_not_found(self):
     ctx = utils.FormattedDict({
         'DOWNLOAD_URL': 'http://server/bins',
         'BUILD_DIR': 'lib',
         'CACHE_DIR': '/cache/dir',
         'WEBDIR': 'htdocs',
         'LIBDIR': 'lib'
     })
     builder = Dingus(_ctx=ctx)
     ct = self.ct.ComposerTool(builder)
     assert not ct.detect()
Example #12
0
 def test_composer_tool_should_compile(self):
     ctx = utils.FormattedDict({
         'DOWNLOAD_URL': 'http://server/bins',
         'BUILD_DIR': 'tests/data/composer',
         'CACHE_DIR': '/cache/dir',
         'PHP_VM': 'will_default_to_php_strategy',
         'WEBDIR': 'htdocs',
         'LIBDIR': 'lib'
     })
     ct = self.extension_module.ComposerExtension(ctx)
     assert ct._should_compile()
Example #13
0
 def test_composer_defaults(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': '/tmp/build',
         'CACHE_DIR': '/tmp/cache',
         'PHP_VM': 'will_default_to_php_strategy',
         'LIBDIR': 'lib'
     })
     ct = self.extension_module.ComposerExtension(ctx)
     eq_('/tmp/build/lib/vendor', ct._ctx['COMPOSER_VENDOR_DIR'])
     eq_('/tmp/build/php/bin', ct._ctx['COMPOSER_BIN_DIR'])
     eq_('/tmp/cache/composer', ct._ctx['COMPOSER_CACHE_DIR'])
 def test_should_compile_service_but_not_supported(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': self.build_dir,
         'PHP_VERSION': '5.6.0',
         'VCAP_SERVICES': {
             "rediscloud": [{"credentials": {}, "label": "rediscloud"}],
             "codizy": [{"credentials": {}, "label": "codizy"}]
         }
     })
     codizy = codizy_extn.CodizyExtension(ctx)
     eq_(False, codizy._should_compile())
Example #15
0
 def test_configure_no_composer(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': 'tests/data/app-1',
         'PHP_EXTENSIONS': ['a', 'b']
     })
     self.ct.ComposerTool.configure(ctx)
     assert 'PHP_EXTENSIONS' in ctx.keys()
     assert list == type(ctx['PHP_EXTENSIONS'])
     assert 2 == len(ctx['PHP_EXTENSIONS'])
     assert 'a' in ctx['PHP_EXTENSIONS']
     assert 'b' in ctx['PHP_EXTENSIONS']
     assert 'openssl' not in ctx['PHP_EXTENSIONS']
Example #16
0
    def test_run_sets_github_oauth_token_if_present(self):
        ctx = utils.FormattedDict({
            'DOWNLOAD_URL': 'http://server/bins',
            'CACHE_HASH_ALGORITHM': 'sha1',
            'BUILD_DIR': '/usr/awesome',
            'PHP_VM': 'php',
            'TMPDIR': tempfile.gettempdir(),
            'LIBDIR': 'lib',
            'CACHE_DIR': 'cache',
            'COMPOSER_GITHUB_OAUTH_TOKEN': 'MADE_UP_TOKEN_VALUE',
            'BP_DIR': ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        environ_stub = Dingus()
        environ_stub._set_return_value('MADE_UP_TOKEN_VALUE')

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
                'composer.extension.utils.rewrite_cfgs': rewrite_stub,
                'os.environ.get': environ_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)

            builder_stub = Dingus(_ctx=ctx)
            ct._builder = builder_stub
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder_stub)

            github_oauth_token_is_valid_stub = Dingus(
                'test_run_sets_github_oauth_token_if_present:'
                'github_oauth_token_is_valid_stub')
            github_oauth_token_is_valid_stub._set_return_value(True)
            ct._github_oauth_token_is_valid = github_oauth_token_is_valid_stub

            ct.run()

            executed_command = stream_output_stub.calls()[0].args[1]

        assert executed_command.find('config') > 0, 'did not see "config"'
        assert executed_command.find('-g') > 0, 'did not see "-g"'
        assert executed_command.find('github-oauth.github.com') > 0, \
            'did not see "github-oauth.github.com"'
        assert executed_command.find('"MADE_UP_TOKEN_VALUE"') > 0, \
            'did not see "MADE_UP_TOKEN_VALUE"'
Example #17
0
    def test_configure_paths_missing(self):
        def fcp_test_json(path):
            tmp = fcp_orig(path)
            return (tmp[0], None)

        def fcp_test_lock(path):
            tmp = fcp_orig(path)
            return (None, tmp[1])

        def fcp_test_none(path):
            return (None, None)

        ctx = utils.FormattedDict({
            'BUILD_DIR':
            'tests/data/composer',
            'WEBDIR':
            '',
            'PHP_56_LATEST':
            '5.6.31',
            'ALL_PHP_VERSIONS':
            ['5.6.31', '5.6.29', '7.0.13', '7.0.14', '7.1.3', '7.1.4']
        })
        fcp_orig = self.extension_module.find_composer_paths
        # test when no composer.json or composer.lock files found
        self.extension_module.find_composer_paths = fcp_test_none
        try:
            self.extension_module.ComposerConfiguration(ctx).configure()
            assert 'PHP_EXTENSIONS' not in ctx.keys()
        finally:
            self.extension_module.find_composer_paths = fcp_orig
        # test when composer.json found, but no composer.lock
        self.extension_module.find_composer_paths = fcp_test_json
        try:
            self.extension_module.ComposerConfiguration(ctx).configure()
            assert 'PHP_EXTENSIONS' in ctx.keys()
            assert 3 == len(ctx['PHP_EXTENSIONS'])
            assert 'openssl' in ctx['PHP_EXTENSIONS']
            assert 'fileinfo' in ctx['PHP_EXTENSIONS']
            assert 'zip' in ctx['PHP_EXTENSIONS']
        finally:
            self.extension_module.find_composer_paths = fcp_orig
        # test when composer.lock found, but no composer.json
        self.extension_module.find_composer_paths = fcp_test_lock
        try:
            self.extension_module.ComposerConfiguration(ctx).configure()
            assert 'PHP_EXTENSIONS' in ctx.keys()
            assert 4 == len(ctx['PHP_EXTENSIONS'])
            assert 'openssl' in ctx['PHP_EXTENSIONS']
            assert 'gd' in ctx['PHP_EXTENSIONS']
            assert 'fileinfo' in ctx['PHP_EXTENSIONS']
            assert 'zip' in ctx['PHP_EXTENSIONS']
        finally:
            self.extension_module.find_composer_paths = fcp_orig
Example #18
0
    def test_composer_tool_run_custom_composer_opts(self):
        ctx = utils.FormattedDict({
            'PHP_VM':
            'php',
            'DOWNLOAD_URL':
            'http://server/bins',
            'CACHE_HASH_ALGORITHM':
            'sha1',
            'BUILD_DIR':
            '/build/dir',
            'CACHE_DIR':
            '/cache/dir',
            'TMPDIR':
            tempfile.gettempdir(),
            'WEBDIR':
            'htdocs',
            'LIBDIR':
            'lib',
            'COMPOSER_INSTALL_OPTIONS': ['--optimize-autoloader'],
            'BP_DIR':
            ''
        })

        instance_stub = Dingus()
        instance_stub._set_return_value(
            """{"rate": {"limit": 60, "remaining": 60}}""")

        stream_output_stub = Dingus()

        rewrite_stub = Dingus()

        builder = Dingus(_ctx=ctx)

        with patches({
                'StringIO.StringIO.getvalue': instance_stub,
                'composer.extension.stream_output': stream_output_stub,
                'composer.extension.utils.rewrite_cfgs': rewrite_stub
        }):
            ct = self.extension_module.ComposerExtension(ctx)
            ct._builder = builder
            ct.composer_runner = \
                self.extension_module.ComposerCommandRunner(ctx, builder)
            ct.run()
            eq_(2, len(builder.move.calls()))
            eq_(1, len(builder.copy.calls()))
            assert rewrite_stub.calls().once()
            rewrite_args = rewrite_stub.calls()[0].args
            assert rewrite_args[0].endswith('php.ini')
            assert 'HOME' in rewrite_args[1]
            assert 'TMPDIR' in rewrite_args[1]
            instCmd = stream_output_stub.calls()[-1].args[1]
            assert instCmd.find('--optimize-autoloader') > 0
    def test_default_version_is_not_in_manifest(self):
        exception = None

        input_dict = utils.FormattedDict()
        input_dict['BP_DIR'] = buildpack_directory()
        create_manifest_file(self.manifest_file, BAD_MANIFEST)

        try:
            CloudFoundryUtil.update_default_version('php', self.manifest_file, input_dict)
        except RuntimeError as e:
            exception = e

        eq_("Error detecting PHP default version", str(exception))
Example #20
0
 def test_configure_composer_without_php_version(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': 'tests/data/composer-no-php',
         'PHP_VERSION': '5.4.31'  # uses bp default
     })
     self.ct.ComposerTool.configure(ctx)
     assert 'PHP_EXTENSIONS' in ctx.keys()
     assert list == type(ctx['PHP_EXTENSIONS'])
     assert 3 == len(ctx['PHP_EXTENSIONS'])
     assert 'openssl' == ctx['PHP_EXTENSIONS'][0]
     assert 'zip' == ctx['PHP_EXTENSIONS'][1]
     assert 'fileinfo' == ctx['PHP_EXTENSIONS'][2]
     assert '5.4.31' == ctx['PHP_VERSION']
 def test_system_files_not_moved_into_webdir(self):
     shutil.copytree('tests/data/app-with-all-possible-system-files-that-should-not-move', self.build_dir)
     setup_webdir_if_it_doesnt_exist(utils.FormattedDict({
         'BUILD_DIR': self.build_dir,
         'WEBDIR': 'htdocs',
         'LIBDIR': 'lib'
     }))
     self.assert_exists(self.build_dir, '.bp')
     self.assert_exists(self.build_dir, '.extensions')
     self.assert_exists(self.build_dir, '.bp-config')
     self.assert_exists(self.build_dir, 'manifest.yml')
     self.assert_exists(self.build_dir, '.profile.d')
     self.assert_exists(self.build_dir, '.profile')
Example #22
0
 def test_configure_does_not_run_when_no_composer_json(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': 'tests/data/app-1',
         'PHP_EXTENSIONS': ['a', 'b']
     })
     config = self.extension_module.ComposerConfiguration(ctx)
     config.configure()
     assert 'PHP_EXTENSIONS' in ctx.keys()
     assert list == type(ctx['PHP_EXTENSIONS'])
     assert 2 == len(ctx['PHP_EXTENSIONS'])
     assert 'a' in ctx['PHP_EXTENSIONS']
     assert 'b' in ctx['PHP_EXTENSIONS']
     assert 'openssl' not in ctx['PHP_EXTENSIONS']
Example #23
0
    def test_configure_runs(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': self.build_dir,
            'PHP_VERSION': '5.4.32'
        })

        class MyExtn(PHPExtensionHelper):
            _configure = Dingus()

            def _should_configure(self):
                return True
        ext = MyExtn(ctx)
        ext.configure()
        eq_(1, len(MyExtn._configure.calls()))
Example #24
0
    def test_compile_doesnt_run(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': self.build_dir,
            'PHP_VERSION': '5.4.32'
        })

        class MyExtn(PHPExtensionHelper):
            _compile = Dingus()

            def _should_compile(self):
                return False
        ext = MyExtn(ctx)
        ext.compile(None)
        eq_(0, len(MyExtn._compile.calls()))
Example #25
0
    def test_service_environment_runs(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': self.build_dir,
            'PHP_VERSION': '5.4.32'
        })

        class MyExtn(PHPExtensionHelper):
            _service_environment = Dingus()

            def _should_compile(self):
                return True
        ext = MyExtn(ctx)
        ext.service_environment()
        eq_(1, len(MyExtn._service_environment.calls()))
Example #26
0
    def test_preprocess_commands_runs(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': self.build_dir,
            'PHP_VERSION': '5.4.32'
        })

        class MyExtn(PHPExtensionHelper):
            _preprocess_commands = Dingus()

            def _should_compile(self):
                return True
        ext = MyExtn(ctx)
        ext.preprocess_commands()
        eq_(1, len(MyExtn._preprocess_commands.calls()))
Example #27
0
 def test_build_composer_environment_no_path(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': '/usr/awesome',
         'PHP_VM': 'php',
         'TMPDIR': 'tmp',
         'LIBDIR': 'lib',
         'CACHE_DIR': 'cache'
     })
     ct = self.extension_module.ComposerExtension(ctx)
     built_environment = ct._build_composer_environment()
     assert 'PATH' in built_environment, "should have PATH set"
     assert "/usr/awesome/php/bin" == built_environment['PATH'], \
         "PATH should contain path to PHP, found [%s]" \
         % built_environment['PATH']
Example #28
0
    def test_service_commands_doesnt_run(self):
        ctx = utils.FormattedDict({
            'BUILD_DIR': self.build_dir,
            'PHP_VERSION': '5.6.30'
        })

        class MyExtn(PHPExtensionHelper):
            _service_commands = Dingus()

            def _should_compile(self):
                return False
        ext = MyExtn(ctx)
        ext.service_commands()
        eq_(0, len(MyExtn._service_commands.calls()))
Example #29
0
 def test_composer_tool_run_custom_composer_opts(self):
     ctx = utils.FormattedDict({
         'PHP_VM':
         'php',
         'DOWNLOAD_URL':
         'http://server/bins',
         'CACHE_HASH_ALGORITHM':
         'sha1',
         'BUILD_DIR':
         '/build/dir',
         'CACHE_DIR':
         '/cache/dir',
         'TMPDIR':
         tempfile.gettempdir(),
         'WEBDIR':
         'htdocs',
         'LIBDIR':
         'lib',
         'COMPOSER_INSTALL_OPTIONS': ['--optimize-autoloader']
     })
     builder = Dingus(_ctx=ctx)
     # patch stream_output method
     old_stream_output = self.extension_module.stream_output
     co = Dingus()
     self.extension_module.stream_output = co
     # patch utils.rewrite_cfg method
     old_rewrite = self.extension_module.utils.rewrite_cfgs
     rewrite = Dingus()
     self.extension_module.utils.rewrite_cfgs = rewrite
     try:
         ct = self.extension_module.ComposerExtension(ctx)
         ct._builder = builder
         ct.run()
         eq_(2, len(builder.move.calls()))
         eq_(1, len(builder.copy.calls()))
         assert rewrite.calls().once()
         rewrite_args = rewrite.calls()[0].args
         assert rewrite_args[0].endswith('php.ini')
         assert 'HOME' in rewrite_args[1]
         assert 'TMPDIR' in rewrite_args[1]
         assert co.calls().once()
         instCmd = co.calls()[0].args[1]
         assert instCmd.find('install') > 0
         assert instCmd.find('--no-progress') > 0
         assert instCmd.find('--no-interaction') == -1
         assert instCmd.find('--no-dev') == -1
         assert instCmd.find('--optimize-autoloader') > 0
     finally:
         self.extension_module.stream_output = old_stream_output
         self.extension_module.utils.rewrite_cfgs = old_rewrite
Example #30
0
 def test_composer_custom_values(self):
     ctx = utils.FormattedDict({
         'BUILD_DIR': '/tmp/build',
         'CACHE_DIR': '/tmp/cache',
         'LIBDIR': 'lib',
         'COMPOSER_VENDOR_DIR': '{BUILD_DIR}/vendor',
         'COMPOSER_BIN_DIR': '{BUILD_DIR}/bin',
         'COMPOSER_CACHE_DIR': '{CACHE_DIR}/custom'
     })
     builder = Dingus(_ctx=ctx)
     ct = self.ct.ComposerTool(builder)
     eq_('/tmp/build/vendor', ct._ctx['COMPOSER_VENDOR_DIR'])
     eq_('/tmp/build/bin', ct._ctx['COMPOSER_BIN_DIR'])
     eq_('/tmp/cache/custom', ct._ctx['COMPOSER_CACHE_DIR'])