From e88604594b7085202945d91d15201d1e8a6849b2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 Oct 2018 14:26:05 +1000 Subject: [PATCH] Project layout (#2411) * Nav bar ideas * Project structure --- app/Ninja/Domain/Helpers/NumberHelper.php | 21 ++++++ app/Ninja/Domain/Invoice/InvoiceTotals.php | 35 +++++++++ c3.php | 63 +--------------- resources/views/header.blade.php | 84 ++++++++++++++++------ tests/Feature/ExampleTest.php | 21 ------ tests/Unit/ExampleTest.php | 19 ----- tests/Unit/NumberTest.php | 34 +++++++++ 7 files changed, 155 insertions(+), 122 deletions(-) create mode 100644 app/Ninja/Domain/Helpers/NumberHelper.php create mode 100644 app/Ninja/Domain/Invoice/InvoiceTotals.php delete mode 100644 tests/Feature/ExampleTest.php delete mode 100644 tests/Unit/ExampleTest.php create mode 100644 tests/Unit/NumberTest.php diff --git a/app/Ninja/Domain/Helpers/NumberHelper.php b/app/Ninja/Domain/Helpers/NumberHelper.php new file mode 100644 index 000000000000..307dcd0cc05c --- /dev/null +++ b/app/Ninja/Domain/Helpers/NumberHelper.php @@ -0,0 +1,21 @@ +invoice = $invoice; + } + + + public function calculate() + { + + } + + private function sumLineItems() + { + + } + + +} diff --git a/c3.php b/c3.php index 80330a1ccded..43e9e64639a6 100644 --- a/c3.php +++ b/c3.php @@ -1,35 +1,28 @@ $value) { $_SERVER["HTTP_X_CODECEPTION_" . strtoupper($key)] = $value; } } } - if (!array_key_exists('HTTP_X_CODECEPTION_CODECOVERAGE', $_SERVER)) { return; } - if (!function_exists('__c3_error')) { function __c3_error($message) { @@ -47,7 +40,6 @@ if (!function_exists('__c3_error')) { setcookie('CODECEPTION_CODECOVERAGE_ERROR', $message); } } - // phpunit codecoverage shimming if (!class_exists('PHP_CodeCoverage') and class_exists('SebastianBergmann\CodeCoverage\CodeCoverage')) { class_alias('SebastianBergmann\CodeCoverage\CodeCoverage', 'PHP_CodeCoverage'); @@ -62,8 +54,7 @@ if (!class_exists('PHP_CodeCoverage') and class_exists('SebastianBergmann\CodeCo // phpunit version if (!class_exists('PHPUnit_Runner_Version') && class_exists('PHPUnit\Runner\Version')) { class_alias('PHPUnit\Runner\Version', 'PHPUnit_Runner_Version'); -} - +} // Autoload Codeception classes if (!class_exists('\\Codeception\\Codecept')) { if (file_exists(__DIR__ . '/codecept.phar')) { @@ -80,11 +71,9 @@ if (!class_exists('\\Codeception\\Codecept')) { __c3_error('Codeception is not loaded. Please check that either PHAR or Composer package can be used'); } } - // Load Codeception Config $config_dist_file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'codeception.dist.yml'; $config_file = realpath(__DIR__) . DIRECTORY_SEPARATOR . 'codeception.yml'; - if (isset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_CONFIG'])) { $config_file = realpath(__DIR__) . DIRECTORY_SEPARATOR . $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_CONFIG']; } @@ -101,12 +90,9 @@ try { } catch (\Exception $e) { __c3_error($e->getMessage()); } - if (!defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) { - // workaround for 'zend_mm_heap corrupted' problem gc_disable(); - $memoryLimit = ini_get('memory_limit'); $requiredMemory = '384M'; if ((substr($memoryLimit, -1) === 'M' && (int)$memoryLimit < (int)$requiredMemory) @@ -115,98 +101,74 @@ if (!defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) { ) { ini_set('memory_limit', $requiredMemory); } - define('C3_CODECOVERAGE_MEDIATE_STORAGE', Codeception\Configuration::logDir() . 'c3tmp'); define('C3_CODECOVERAGE_PROJECT_ROOT', Codeception\Configuration::projectDir()); define('C3_CODECOVERAGE_TESTNAME', $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE']); - function __c3_build_html_report(PHP_CodeCoverage $codeCoverage, $path) { $writer = new PHP_CodeCoverage_Report_HTML(); $writer->process($codeCoverage, $path . 'html'); - if (file_exists($path . '.tar')) { unlink($path . '.tar'); } - $phar = new PharData($path . '.tar'); $phar->setSignatureAlgorithm(Phar::SHA1); $files = $phar->buildFromDirectory($path . 'html'); array_map('unlink', $files); - if (in_array('GZ', Phar::getSupportedCompression())) { if (file_exists($path . '.tar.gz')) { unlink($path . '.tar.gz'); } - $phar->compress(\Phar::GZ); - // close the file so that we can rename it unset($phar); - unlink($path . '.tar'); rename($path . '.tar.gz', $path . '.tar'); } - return $path . '.tar'; } - function __c3_build_clover_report(PHP_CodeCoverage $codeCoverage, $path) { $writer = new PHP_CodeCoverage_Report_Clover(); $writer->process($codeCoverage, $path . '.clover.xml'); - return $path . '.clover.xml'; } - function __c3_build_crap4j_report(PHP_CodeCoverage $codeCoverage, $path) { $writer = new PHP_CodeCoverage_Report_Crap4j(); $writer->process($codeCoverage, $path . '.crap4j.xml'); - return $path . '.crap4j.xml'; } - function __c3_build_phpunit_report(PHP_CodeCoverage $codeCoverage, $path) { $writer = new PHP_CodeCoverage_Report_XML(\PHPUnit_Runner_Version::id()); $writer->process($codeCoverage, $path . 'phpunit'); - if (file_exists($path . '.tar')) { unlink($path . '.tar'); } - $phar = new PharData($path . '.tar'); $phar->setSignatureAlgorithm(Phar::SHA1); $files = $phar->buildFromDirectory($path . 'phpunit'); array_map('unlink', $files); - if (in_array('GZ', Phar::getSupportedCompression())) { if (file_exists($path . '.tar.gz')) { unlink($path . '.tar.gz'); } - $phar->compress(\Phar::GZ); - // close the file so that we can rename it unset($phar); - unlink($path . '.tar'); rename($path . '.tar.gz', $path . '.tar'); } - return $path . '.tar'; } - function __c3_send_file($filename) { if (!headers_sent()) { readfile($filename); } - return __c3_exit(); } - /** * @param $filename * @param bool $lock Lock the file for writing? @@ -226,12 +188,11 @@ if (!defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) { } else { $phpCoverage = unserialize(file_get_contents($filename)); } - + return array($phpCoverage, $file); } else { $phpCoverage = new PHP_CodeCoverage(); } - if (isset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_SUITE'])) { $suite = $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_SUITE']; try { @@ -242,7 +203,6 @@ if (!defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) { } else { $settings = \Codeception\Configuration::config(); } - try { \Codeception\Coverage\Filter::setup($phpCoverage) ->whiteList($settings) @@ -250,10 +210,8 @@ if (!defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) { } catch (Exception $e) { __c3_error($e->getMessage()); } - return array($phpCoverage, $file); } - function __c3_exit() { if (!isset($_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'])) { @@ -261,37 +219,28 @@ if (!defined('C3_CODECOVERAGE_MEDIATE_STORAGE')) { } return null; } - function __c3_clear() { \Codeception\Util\FileSystem::doEmptyDir(C3_CODECOVERAGE_MEDIATE_STORAGE); } } - if (!is_dir(C3_CODECOVERAGE_MEDIATE_STORAGE)) { if (mkdir(C3_CODECOVERAGE_MEDIATE_STORAGE, 0777, true) === false) { __c3_error('Failed to create directory "' . C3_CODECOVERAGE_MEDIATE_STORAGE . '"'); } } - // evaluate base path for c3-related files $path = realpath(C3_CODECOVERAGE_MEDIATE_STORAGE) . DIRECTORY_SEPARATOR . 'codecoverage'; - $requested_c3_report = (strpos($_SERVER['REQUEST_URI'], 'c3/report') !== false); - $complete_report = $current_report = $path . '.serialized'; if ($requested_c3_report) { set_time_limit(0); - $route = ltrim(strrchr($_SERVER['REQUEST_URI'], '/'), '/'); - if ($route === 'clear') { __c3_clear(); return __c3_exit(); } - list($codeCoverage, ) = __c3_factory($complete_report); - switch ($route) { case 'html': try { @@ -329,21 +278,18 @@ if ($requested_c3_report) { } return __c3_exit(); } - } else { list($codeCoverage, ) = __c3_factory(null); $codeCoverage->start(C3_CODECOVERAGE_TESTNAME); if (!array_key_exists('HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG', $_SERVER)) { register_shutdown_function( function () use ($codeCoverage, $current_report) { - $codeCoverage->stop(); if (!file_exists(dirname($current_report))) { // verify directory exists if (!mkdir(dirname($current_report), 0777, true)) { __c3_error("Can't write CodeCoverage report into $current_report"); } } - // This will either lock the existing report for writing and return it along with a file pointer, // or return a fresh PHP_CodeCoverage object without a file pointer. We'll merge the current request // into that coverage object, write it to disk, and release the lock. By doing this in the end of @@ -356,10 +302,8 @@ if ($requested_c3_report) { // In addition, by locking the file for exclusive writing, we make sure no other request try to // read/write to the file at the same time as this request (leading to a corrupt file). flock() is a // blocking call, so it waits until an exclusive lock can be acquired before continuing. - list($existingCodeCoverage, $file) = __c3_factory($current_report, true); $existingCodeCoverage->merge($codeCoverage); - if ($file === null) { file_put_contents($current_report, serialize($existingCodeCoverage), LOCK_EX); } else { @@ -373,5 +317,4 @@ if ($requested_c3_report) { ); } } - -// @codeCoverageIgnoreEnd +// @codeCoverageIgnoreEnd \ No newline at end of file diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 6dd5ea552f67..844dba6b0bb2 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -1,11 +1,11 @@