Skip to content

Commit

Permalink
Use PROJECT_ROOT environment for development project dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
janbuecker committed Feb 5, 2019
1 parent fab3da3 commit 26cf467
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 6 deletions.
2 changes: 2 additions & 0 deletions phpstan.neon
Expand Up @@ -11,6 +11,8 @@ parameters:
- %rootDir%/../../src/Core/Framework/Demodata/Generator/ProductGenerator.php
- %rootDir%/../../src/Core/Framework/Demodata/Generator/ProductStreamGenerator.php
- %rootDir%/../../src/Core/Framework/Faker/Commerce.php
- %rootDir%/../../src/Core/TestBootstrap.php
- %rootDir%/../../src/Core/System/Test/SystemConfig/TestKernel.php
- %rootDir%/../../src/Docs/*
ignoreErrors:
- '#PHPDoc tag @param for parameter.*EntityDefinition.*is not subtype of native type string#'
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -2,7 +2,7 @@

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.1/phpunit.xsd"
bootstrap="../../../tests/TestBootstrap.php"
bootstrap="src/Core/TestBootstrap.php"
>

<php>
Expand Down
3 changes: 2 additions & 1 deletion src/Administration/Resources/administration/build/utils.js
Expand Up @@ -5,6 +5,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const dotenv = require('dotenv');
const fs = require('fs');
const process = require('process');

const MiniCssExtractPlugin = require("mini-css-extract-plugin");

Expand All @@ -15,7 +16,7 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
* @returns {String}
*/
exports.resolveFromRootPath = function(directory) {
return path.join(__dirname, '../../../../../../../../', directory);
return path.join(process.env.PROJECT_ROOT, directory);
};

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Administration/Resources/administration/jsdoc.config.js
@@ -1,3 +1,6 @@
const path = require('path');
const process = require('process');

module.exports = {
tags: {
allowUnknownTags: true,
Expand All @@ -12,7 +15,7 @@ module.exports = {
}
},
opts: {
destination: '../../../../../../../build/artifacts/jsdoc',
destination: path.join(process.env.PROJECT_ROOT, '/build/artifacts/jsdoc'),
encoding: 'utf8',
private: true,
recurse: true,
Expand Down
Expand Up @@ -4,8 +4,9 @@
// https://github.com/webpack/karma-webpack
const webpackConfig = require('../../build/webpack.test.conf');
const path = require('path');
const process = require('process');

const artifactsPath = path.join(__dirname, '../../../../../../../../../build/artifacts');
const artifactsPath = path.join(process.env.PROJECT_ROOT, '/build/artifacts');

module.exports = function (config) {
config.set({
Expand Down
@@ -1,9 +1,10 @@
const fs = require('fs');
const path = require('path');
const fileParser = require(__dirname + '/lib/file-parser');
const process = require('process');

function getPathFromRoot(directory) {
return path.join(__dirname, '../../../../../../../', directory);
return path.join(process.env.PROJECT_ROOT, directory);
}

console.log();
Expand Down
19 changes: 18 additions & 1 deletion src/Core/System/Test/SystemConfig/TestKernel.php
Expand Up @@ -10,9 +10,26 @@

class TestKernel extends Kernel
{
/**
* @var string
*/
private $projectDir;

public function getProjectDir()
{
return __DIR__ . '/../../../../../../../../';
if ($this->projectDir === null) {
$r = new \ReflectionClass($_SERVER['KERNEL_CLASS']);
$dir = $rootDir = \dirname($r->getFileName());
while (!file_exists($dir . '/composer.json')) {
if ($dir === \dirname($dir)) {
return $this->projectDir = $rootDir;
}
$dir = \dirname($dir);
}
$this->projectDir = $dir;
}

return $this->projectDir;
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/Core/TestBootstrap.php
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

function getProjectDir(): string
{
$r = new \ReflectionClass($_SERVER['KERNEL_CLASS']);
$dir = $rootDir = \dirname($r->getFileName());
while (!file_exists($dir . '/composer.json')) {
if ($dir === \dirname($dir)) {
return $rootDir;
}
$dir = \dirname($dir);
}

return $dir;
}

$projectDir = getProjectDir();

require_once $projectDir . '/vendor/autoload.php';

use Symfony\Component\Dotenv\Dotenv;

if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load($projectDir . '/.env');

putenv('DATABASE_URL=' . getenv('DATABASE_URL') . '_test');

0 comments on commit 26cf467

Please sign in to comment.