Skip to content

Commit

Permalink
Last minutes changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlucas committed Aug 26, 2020
1 parent 486a880 commit 7185ded
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
12 changes: 0 additions & 12 deletions src/Stubs/Response.stubphp

This file was deleted.

28 changes: 15 additions & 13 deletions src/Test/CodeceptionModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@ class CodeceptionModule extends BaseModule
'default_dir' => 'tests/_run/',
];

public const TWIG_TEMPLATES_DIR = 'templates';

/**
* @Given I have the following :templateName template :code
*/
public function haveTheFollowingTemplate(string $templateName, string $code): void
{
$rootDirectory = rtrim($this->config['default_dir'], '/');
$templateRootDirectory = $rootDirectory.'/templates';
$rootDirectory = rtrim($this->config['default_dir'], DIRECTORY_SEPARATOR);
$templateRootDirectory = $rootDirectory.DIRECTORY_SEPARATOR.self::TWIG_TEMPLATES_DIR;
if (!file_exists($templateRootDirectory)) {
mkdir($templateRootDirectory);
}

file_put_contents(
$templateRootDirectory.'/'.$templateName,
$templateRootDirectory.DIRECTORY_SEPARATOR.$templateName,
$code
);
}
Expand All @@ -49,10 +51,10 @@ public function haveTheFollowingTemplate(string $templateName, string $code): vo
*/
public function haveTheTemplateCompiled(string $templateName, string $cacheDirectory): void
{
$rootDirectory = rtrim($this->config['default_dir'], '/');
$cacheDirectory = $rootDirectory.'/'.ltrim($cacheDirectory, '/');
$rootDirectory = rtrim($this->config['default_dir'], DIRECTORY_SEPARATOR);
$cacheDirectory = $rootDirectory.DIRECTORY_SEPARATOR.ltrim($cacheDirectory, DIRECTORY_SEPARATOR);
if (!file_exists($cacheDirectory)) {
mkdir($cacheDirectory, 0777, true);
mkdir($cacheDirectory, 0600, true);
}

$twigEnvironment = self::getEnvironment($rootDirectory, $cacheDirectory);
Expand Down Expand Up @@ -86,15 +88,13 @@ public function haveADependencySatisfied(string $package, string $versionConstra
}
}

public const TEMPLATE_DIR = 'templates';

public static function getEnvironment(string $rootDirectory, string $cacheDirectory): Environment
private static function getEnvironment(string $rootDirectory, string $cacheDirectory): Environment
{
if (!file_exists($rootDirectory.'/'.self::TEMPLATE_DIR)) {
mkdir($rootDirectory.'/'.self::TEMPLATE_DIR);
if (!file_exists($rootDirectory.DIRECTORY_SEPARATOR.self::TWIG_TEMPLATES_DIR)) {
mkdir($rootDirectory.DIRECTORY_SEPARATOR.self::TWIG_TEMPLATES_DIR);
}

$loader = new FilesystemLoader(self::TEMPLATE_DIR, $rootDirectory);
$loader = new FilesystemLoader(self::TWIG_TEMPLATES_DIR, $rootDirectory);

if (!is_dir($cacheDirectory)) {
throw new InvalidArgumentException(sprintf('The %s twig cache directory does not exist or is not readable.', $cacheDirectory));
Expand All @@ -109,7 +109,9 @@ public static function getEnvironment(string $rootDirectory, string $cacheDirect
'strict_variables' => false,
]);

// the following is a trick to force the twig env to change
// The following is a trick to have a different twig cache hash everytime, preventing collisions from one test to another :
// the extension construction has to be evaled so the class name will change each time,
// making the env calculate a different Twig\Environment::$optionHash (which is partly based on the extension names).
/** @var AbstractExtension $ext */
$ext = eval('use Twig\Extension\AbstractExtension; return new class() extends AbstractExtension {};');
$twigEnvironment->addExtension($ext);
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/AnalyzedTemplatesTainter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Twig\Environment;

/**
* This hook add paths from all taint sources of a `Twig\Environment::render()` call to all taint sinks of the corresponding template.
* This hook adds paths from all taint sources going to a `Twig\Environment::render()` call to all taint sinks of the corresponding template.
* The TemplateFileAnalyzer should be declared in configuration.
*/
class AnalyzedTemplatesTainter implements AfterMethodCallAnalysisInterface
Expand Down

0 comments on commit 7185ded

Please sign in to comment.