Skip to content

Commit

Permalink
Merge pull request #145 from mychidarko/v3.x-dev
Browse files Browse the repository at this point in the history
V3.x dev
  • Loading branch information
mychidarko authored Sep 10, 2022
2 parents 67713a4 + 6001f4a commit dea6c86
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 👷 Fix styling
commit_message: 'chore: fix styling'
189 changes: 127 additions & 62 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"prefer-stable": true,
"require": {
"leafs/http": "^2.0",
"leafs/router": "^0.1.6",
"leafs/router": "^0.1.7",
"leafs/anchor": "^1.2",
"leafs/exception": "^3.0"
},
Expand Down
8 changes: 4 additions & 4 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function app()
*/
function _env($key, $default = null)
{
$item = getenv($key);
$env = array_merge(getenv() ?? [], $_ENV ?? []);

if (!isset($_ENV[$key]) || (isset($_ENV[$key]) && $_ENV[$key] == null)) {
$item = $default;
if (!isset($env[$key]) || (isset($env[$key]) && $env[$key] === null)) {
$env[$key] = $default;
}

return $item;
return $env[$key] ?? $default;
}
}
14 changes: 14 additions & 0 deletions tests/app.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,17 @@ public function customMethod()

expect($leafInstance1->response->customMethod())->toBe('This is some test response');
});

test('get route info', function () {
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/homepage';

$routePath = '/homepage';

app()->get($routePath, function () use ($routePath) {
$routeData = app()->getRoute();
expect($routeData['path'])->toBe($routePath);
});

app()->run();
});
4 changes: 4 additions & 0 deletions tests/config.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@
expect($homeConfig['key'])->toBe('2');
expect(app()->config('home.key'))->toBe('2');
});

test('Env is successfully retrieved', function () {
expect(_env('USER', false))->toBe(getenv('USER'));
});

0 comments on commit dea6c86

Please sign in to comment.