src/Service/MelisPhpUnitToolService.php
public function init($moduleName, $moduleTestName, $unitTestPath = 'test')
    {
        $moduleSvc = $this->getServiceLocator()->get('ModulesService');
        $modulePath = $moduleSvc->getModulePath($moduleName);
        $bootstrapSavePath = $modulePath.'/'.$unitTestPath.'/Bootstrap.php';
        $xmlSavePath = $modulePath.'/'.$unitTestPath.'/phpunit.xml';
        $moduleTestSavePath = $modulePath.'/'.$unitTestPath.'/'.$moduleTestName.'/Controller';
        $testSavePath = $modulePath.'/'.$unitTestPath;

        $this->setAppConfig();
        if(file_exists($modulePath) && file_exists($testSavePath)) {

            $bootstrapTemplate = $_SERVER['DOCUMENT_ROOT'] . '/../test/tpl/BootstrapTemplate';
            $puControllerTemplate = $_SERVER['DOCUMENT_ROOT'] . '/../test/tpl/PHPUnitControllTest';
            $bootstrapContent = '';
            $xmlContent = '';
            if(file_exists($bootstrapTemplate)) {

                $bootstrapContent = file_get_contents($bootstrapTemplate);
                $bootstrapContent = sprintf($bootstrapContent, $moduleTestName);
                file_put_contents($bootstrapSavePath, $bootstrapContent);
                $xml = $_SERVER['DOCUMENT_ROOT'].'/../test/tpl/phpunitxmlTemplate';
                if(file_exists($xml)) {
                    $xmlContent = file_get_contents($xml);
                    $xmlContent = str_replace('{{moduleName}}', $moduleTestName, $xmlContent);
                    file_put_contents($xmlSavePath, $xmlContent);
                }

                if(!file_exists($moduleTestSavePath)) {
                    mkdir($moduleTestSavePath, 0777, true);

                    $tmpcontrollerName = explode("Test", $moduleTestName);
                    if(is_array($tmpcontrollerName) && !empty($tmpcontrollerName)) {
                        $controllerName = $tmpcontrollerName[0] . 'ControllerTest';
                        if(!file_exists($moduleTestSavePath.'/'.$controllerName.'.php')) {
                            $ctrlTpl = file_get_contents($puControllerTemplate);
                            $ctrlTpl = str_replace(array(
                                '{{moduleTestName}}',
                                '{{moduleTestControllerName}}',
                                '{{tableFunctions}}',
                                '{{moduleName}}'
                            ), array($moduleTestName, $controllerName, $this->getDbMethods($moduleName), $moduleName), $ctrlTpl);
                            file_put_contents($moduleTestSavePath.'/'.$controllerName.'.php', $ctrlTpl);
                        }
                    }
                }
            }
        }
        else {
            mkdir($testSavePath, 0777, true);
            $this->init($moduleName, $moduleTestName, $unitTestPath);
        }

        // Make sure the files are existing
        if(file_exists($bootstrapSavePath) && file_exists($xmlSavePath) && file_exists($moduleTestSavePath)) {
            return true;
        }

        return false;

    }
public function init($moduleName, $moduleTestName, $unitTestPath = 'test')
    {
        $moduleSvc = $this->getServiceLocator()->get('ModulesService');
        $modulePath = $moduleSvc->getModulePath($moduleName);
        $bootstrapSavePath = $modulePath.'/'.$unitTestPath.'/Bootstrap.php';
        $xmlSavePath = $modulePath.'/'.$unitTestPath.'/phpunit.xml';
        $moduleTestSavePath = $modulePath.'/'.$unitTestPath.'/'.$moduleTestName.'/Controller';
        $testSavePath = $modulePath.'/'.$unitTestPath;

        $this->setAppConfig();
        if(file_exists($modulePath) && file_exists($testSavePath)) {

            $bootstrapTemplate = $_SERVER['DOCUMENT_ROOT'] . '/../test/tpl/BootstrapTemplate';
            $puControllerTemplate = $_SERVER['DOCUMENT_ROOT'] . '/../test/tpl/PHPUnitControllTest';
            $bootstrapContent = '';
            $xmlContent = '';
            if(file_exists($bootstrapTemplate)) {

                $bootstrapContent = file_get_contents($bootstrapTemplate);
                $bootstrapContent = sprintf($bootstrapContent, $moduleTestName);
                file_put_contents($bootstrapSavePath, $bootstrapContent);
                $xml = $_SERVER['DOCUMENT_ROOT'].'/../test/tpl/phpunitxmlTemplate';
                if(file_exists($xml)) {
                    $xmlContent = file_get_contents($xml);
                    $xmlContent = str_replace('{{moduleName}}', $moduleTestName, $xmlContent);
                    file_put_contents($xmlSavePath, $xmlContent);
                }

                if(!file_exists($moduleTestSavePath)) {
                    mkdir($moduleTestSavePath, 0777, true);

                    $tmpcontrollerName = explode("Test", $moduleTestName);
                    if(is_array($tmpcontrollerName) && !empty($tmpcontrollerName)) {
                        $controllerName = $tmpcontrollerName[0] . 'ControllerTest';
                        if(!file_exists($moduleTestSavePath.'/'.$controllerName.'.php')) {
                            $ctrlTpl = file_get_contents($puControllerTemplate);
                            $ctrlTpl = str_replace(array(
                                '{{moduleTestName}}',
                                '{{moduleTestControllerName}}',
                                '{{tableFunctions}}',
                                '{{moduleName}}'
                            ), array($moduleTestName, $controllerName, $this->getDbMethods($moduleName), $moduleName), $ctrlTpl);
                            file_put_contents($moduleTestSavePath.'/'.$controllerName.'.php', $ctrlTpl);
                        }
                    }
                }
            }
        }
        else {
            mkdir($testSavePath, 0777, true);
            $this->init($moduleName, $moduleTestName, $unitTestPath);
        }

        // Make sure the files are existing
        if(file_exists($bootstrapSavePath) && file_exists($xmlSavePath) && file_exists($moduleTestSavePath)) {
            return true;
        }

        return false;

    }
public function init ( $ moduleName , $ moduleTestName , $ unitTestPath = 'test' ) { $ moduleSvc = $ this -> getServiceLocator ( ) -> get ( 'ModulesService' ) ; $ modulePath = $ moduleSvc -> getModulePath ( $ moduleName ) ; $ bootstrapSavePath = $ modulePath . '/' . $ unitTestPath . '/Bootstrap.php' ; $ xmlSavePath = $ modulePath . '/' . $ unitTestPath . '/phpunit.xml' ; $ moduleTestSavePath = $ modulePath . '/' . $ unitTestPath . '/' . $ moduleTestName . '/Controller' ; $ testSavePath = $ modulePath . '/' . $ unitTestPath ; $ this -> setAppConfig ( ) ; if ( file_exists ( $ modulePath ) && file_exists ( $ testSavePath ) ) { $ bootstrapTemplate = $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../test/tpl/BootstrapTemplate' ; $ puControllerTemplate = $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../test/tpl/PHPUnitControllTest' ; $ bootstrapContent = '' ; $ xmlContent = '' ; if ( file_exists ( $ bootstrapTemplate ) ) { $ bootstrapContent = file_get_contents ( $ bootstrapTemplate ) ; $ bootstrapContent = sprintf ( $ bootstrapContent , $ moduleTestName ) ; file_put_contents ( $ bootstrapSavePath , $ bootstrapContent ) ; $ xml = $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../test/tpl/phpunitxmlTemplate' ; if ( file_exists ( $ xml ) ) { $ xmlContent = file_get_contents ( $ xml ) ; $ xmlContent = str_replace ( '{{moduleName}}' , $ moduleTestName , $ xmlContent ) ; file_put_contents ( $ xmlSavePath , $ xmlContent ) ; } if ( ! file_exists ( $ moduleTestSavePath ) ) { mkdir ( $ moduleTestSavePath , 0777 , true ) ; $ tmpcontrollerName = explode ( "Test" , $ moduleTestName ) ; if ( is_array ( $ tmpcontrollerName ) && ! empty ( $ tmpcontrollerName ) ) { $ controllerName = $ tmpcontrollerName [ 0 ] . 'ControllerTest' ; if ( ! file_exists ( $ moduleTestSavePath . '/' . $ controllerName . '.php' ) ) { $ ctrlTpl = file_get_contents ( $ puControllerTemplate ) ; $ ctrlTpl = str_replace ( array ( '{{moduleTestName}}' , '{{moduleTestControllerName}}' , '{{tableFunctions}}' , '{{moduleName}}' ) , array ( $ moduleTestName , $ controllerName , $ this -> getDbMethods ( $ moduleName ) , $ moduleName ) , $ ctrlTpl ) ; file_put_contents ( $ moduleTestSavePath . '/' . $ controllerName . '.php' , $ ctrlTpl ) ; } } } } } else { mkdir ( $ testSavePath , 0777 , true ) ; $ this -> init ( $ moduleName , $ moduleTestName , $ unitTestPath ) ; } // Make sure the files are existing if ( file_exists ( $ bootstrapSavePath ) && file_exists ( $ xmlSavePath ) && file_exists ( $ moduleTestSavePath ) ) { return true ; } return false ; }
Bootstrap.php file will be created inside the test folder
@param String $moduleName
@param String $testModuleName
@param String $unitTestPath
Bootstrap . php file will be created inside the test folder