From 2949ad04fcf6836bdaea675bc0203657189fa960 Mon Sep 17 00:00:00 2001 From: Sarah Mount Date: Fri, 22 Sep 2023 10:36:48 +0100 Subject: [PATCH] QUESTION ABOUT MOCKING TESTS --- tests/Helpers.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/Helpers.php b/tests/Helpers.php index 53290d4..8403ba4 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -117,7 +117,39 @@ private function getProjectDirectory($dir) private function getDir() { $root = \org\bovigo\vfs\vfsStream::setup(); - - return $root->url(); + $dir = $root->url(); + + // + // None of these attempts to avoid the tests failing due to missing + // directories work, they don't work if you put them directly + // in the tests, but file_exists() returns true until it gets to + // WhippetHelpers. I think this is because in whippet_init() we ignore + // any directories that have been passed in, and search for a whippet.json + // file on the actual disk, so the virtual disk is never read. + // + // We seem to have more than one way of knowing which dir is the project + // repo, and whippet_init() recurses the directory to find a .json file. + // This means that the virtual fs that we use to mock the tests will not + // be used, hence the errors. I think we should probably remove that + // code, but I'm not sure if anything is relying on it... + // + + + mkdir($dir.'/config'); + touch($dir.'/config/application.json'); + mkdir($dir.'/wp-content'); + mkdir($dir.'/wp-content/plugins'); + // // if (!file_exists("{$dir}/config")) { + // // printf("FS SAYS NOPE"); + // // } + // \org\bovigo\vfs\vfsStream::newDirectory($dir.'/config'); + // // \org\bovigo\vfs\vfsStream::newDirectory($dir.'/wp-content/plugins'); + + // // mkdir(\org\bovigo\vfs\vfsStream::url($dir.'/wp-content/plugins')); + // mkdir(\org\bovigo\vfs\vfsStream::url($dir.'/config')); + + // \org\bovigo\vfs\vfsStream::create(['config' => [], ['wp-content' => ['plugins' => []]]], $root); + + return $dir; } }