Project layout (#2411)

* Nav bar ideas

* Project structure
This commit is contained in:
David Bomba 2018-10-05 14:26:05 +10:00 committed by GitHub
parent 0503887629
commit e88604594b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 155 additions and 122 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace App\Ninja\Domain\Helpers;
/**
* Class NumberHelper
* @package App\Ninja
*/
class NumberHelper
{
/**
* @param float $value
* @param int $precision
* @return float
*/
public static function roundValue(float $value, int $precision = 2) : float
{
return round($value, $precision, PHP_ROUND_HALF_UP);
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Ninja\Domain\Invoice;
/**
* Class InvoiceTotals
*/
class InvoiceTotals
{
protected $invoice;
/**
* InvoiceTotals constructor.
* @param $invoice
*/
public function __construct($invoice)
{
$this->invoice = $invoice;
}
public function calculate()
{
}
private function sumLineItems()
{
}
}

63
c3.php
View File

@ -1,35 +1,28 @@
<?php
// @codingStandardsIgnoreFile
// @codeCoverageIgnoreStart
/**
* C3 - Codeception Code Coverage
*
* @author tiger
*/
// $_SERVER['HTTP_X_CODECEPTION_CODECOVERAGE_DEBUG'] = 1;
if (isset($_COOKIE['CODECEPTION_CODECOVERAGE'])) {
$cookie = json_decode($_COOKIE['CODECEPTION_CODECOVERAGE'], true);
// fix for improperly encoded JSON in Code Coverage cookie with WebDriver.
// @see https://github.com/Codeception/Codeception/issues/874
if (!is_array($cookie)) {
$cookie = json_decode($cookie, true);
}
if ($cookie) {
foreach ($cookie as $key => $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

View File

@ -1,11 +1,11 @@
<script>
// https://bulma.io/documentation/components/navbar/
document.addEventListener('DOMContentLoaded', () => {
// https://bulma.io/documentation/components/navbar/
document.addEventListener('DOMContentLoaded', () => {
// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
// Get all "navbar-burger" elements
const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
@ -14,25 +14,25 @@ document.addEventListener('DOMContentLoaded', () => {
$navbarBurgers.forEach( el => {
el.addEventListener('click', () => {
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Get the target from the "data-target" attribute
const target = el.dataset.target;
const $target = document.getElementById(target);
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
});
});
}
});
});
</script>
<header class="hero is-light">
<div class="hero-head">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://bulma.io">
<a class="navbar-item" href="https://app.invoiceninja.com/">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">
</a>
@ -45,13 +45,6 @@ document.addEventListener('DOMContentLoaded', () => {
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Documentation
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
@ -74,10 +67,57 @@ document.addEventListener('DOMContentLoaded', () => {
</a>
</div>
</div>
<div class="navbar-item field has-addons">
<div class="control has-icons-left">
<input class="input" type="email" placeholder="Search">
<span class="icon is-small is-left">
<i class="fa fa-search"></i>
</span>
</div>
</div>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Company Switcher</a>
<div class="navbar-dropdown is-right is-boxed">
<a class="navbar-item" href="/switch">
<span class="icon"><i class="fa fa-gear"></i></span>
<span>co 1</span>
</a>
<a class="navbar-item" href="/switch">
<span class="icon"><i class="fa fa-gear"></i></span>
<span>co 2</span>
</a>
<a class="navbar-item" href="/switch">
<span class="icon"><i class="fa fa-gear"></i></span>
<span>co 3</span>
</a>
<div class="navbar-divider"></div>
<a class="navbar-item" href="/log-out">
<span class="icon"><i class="fa fa-sign-out"></i></span>
<span>Add Co</span>
</a>
</div>
</div>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Ninja User</a>
<div class="navbar-dropdown is-right is-boxed">
<a class="navbar-item" href="/settings">
<span class="icon"><i class="fa fa-gear"></i></span>
<span>Settings</span>
</a>
<div class="navbar-divider"></div>
<a class="navbar-item" href="/log-out">
<span class="icon"><i class="fa fa-sign-out"></i></span>
<span>Log out</span>
</a>
</div>
<div class="buttons">
<a class="button is-primary">
<strong>Sign up</strong>

View File

@ -1,21 +0,0 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}

View File

@ -1,19 +0,0 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}

34
tests/Unit/NumberTest.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace Tests\Unit;
use App\Ninja\Domain\Helpers\NumberHelper;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class NumberTest extends TestCase
{
public function testRoundingThreeLow()
{
$rounded = NumberHelper::roundValue(3.144444444444, 3);
$this->assertEquals(3.144, $rounded);
}
public function testRoundingThreeHigh()
{
$rounded = NumberHelper::roundValue(3.144944444444, 3);
$this->assertEquals(3.145, $rounded);
}
public function testRoundingTwoLow()
{
$rounded = NumberHelper::roundValue(2.145);
$this->assertEquals(2.15, $rounded);
}
}