Skip to content

Commit 15d0cfe

Browse files
committed
Add parseUrlPath tests
1 parent d4b521d commit 15d0cfe

File tree

4 files changed

+136
-3
lines changed

4 files changed

+136
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
.DS_Store
66
.phpunit.result.cache
77
composer.lock
8+
clover.xml
9+
.phpunit.cache

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ RUN apt-get update && apt-get install -y \
1313
# Install PHP extensions
1414
RUN docker-php-ext-install pdo pdo_sqlite
1515

16+
# Install xdebug code coverage driver
17+
RUN pecl install xdebug \
18+
&& docker-php-ext-enable xdebug
19+
20+
RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
21+
1622
# Install Composer
1723
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
1824

tests/Unit/Support/HelpersTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Tests\Unit\Support;
44

55
use Illuminate\Support\Facades\Config;
6+
use Illuminate\Support\Facades\Route;
67
use Illuminate\Support\Facades\Storage;
78
use InternetGuru\LaravelCommon\Support\Helpers;
89
use Mockery;
@@ -13,9 +14,8 @@ class HelpersTest extends TestCase
1314
protected function setUp(): void
1415
{
1516
parent::setUp();
16-
$this->app['router']->get('/', function () {
17-
return 'Home';
18-
})->name('home');
17+
// Define routes for testing
18+
Route::get('/', function () {})->name('home');
1919
}
2020

2121
protected function tearDown(): void
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
namespace Tests\Unit\Support;
4+
5+
use Illuminate\Support\Facades\Route;
6+
use InternetGuru\LaravelCommon\Support\Helpers;
7+
use Tests\TestCase;
8+
9+
class ParseUrlPathTest extends TestCase
10+
{
11+
protected function setUp(): void
12+
{
13+
parent::setUp();
14+
// Define routes for testing
15+
Route::get('/', function () {})->name('home');
16+
Route::get('/about', function () {})->name('about');
17+
Route::get('/products', function () {})->name('products.index');
18+
Route::get('/products/{category}', function () {})->name('products.category');
19+
Route::get('/products/{category}/{item}', function () {})->name('products.item');
20+
}
21+
22+
public function testParseUrlPathRoot()
23+
{
24+
$this->get('/');
25+
26+
$result = Helpers::parseUrlPath();
27+
28+
$expected = [
29+
[
30+
'uri' => '/',
31+
'translation' => __('navig.home'),
32+
],
33+
];
34+
35+
$this->assertEquals($expected, $result);
36+
}
37+
38+
public function testParseUrlPathSimple()
39+
{
40+
$this->get('/about');
41+
42+
$result = Helpers::parseUrlPath();
43+
44+
$expected = [
45+
[
46+
'uri' => '/',
47+
'translation' => __('navig.home'),
48+
],
49+
[
50+
'uri' => '/about',
51+
'translation' => __('navig.about'),
52+
],
53+
];
54+
55+
$this->assertEquals($expected, $result);
56+
}
57+
58+
public function testParseUrlPathNested()
59+
{
60+
$this->get('/products/electronics/laptops');
61+
62+
$result = Helpers::parseUrlPath();
63+
64+
$expected = [
65+
[
66+
'uri' => '/',
67+
'translation' => __('navig.home'),
68+
],
69+
[
70+
'uri' => '/products',
71+
'translation' => __('navig.products.index'),
72+
],
73+
[
74+
'uri' => '/products/electronics',
75+
'translation' => __('navig.products.category'),
76+
],
77+
[
78+
'uri' => '/products/electronics/laptops',
79+
'translation' => __('navig.products.item'),
80+
],
81+
];
82+
83+
$this->assertEquals($expected, $result);
84+
}
85+
86+
public function testParseUrlPathWithSkip()
87+
{
88+
$this->get('/admin/dashboard');
89+
90+
$result = Helpers::parseUrlPath('home', skipFirst: 1);
91+
92+
$expected = [
93+
[
94+
'uri' => '/',
95+
'translation' => __('navig.home'),
96+
],
97+
[
98+
'uri' => '',
99+
'translation' => __('navig.dashboard'),
100+
],
101+
];
102+
103+
$this->assertEquals($expected, $result);
104+
}
105+
106+
public function testParseUrlPathNonExistentRoute()
107+
{
108+
$this->get('/non-existent');
109+
110+
$result = Helpers::parseUrlPath();
111+
112+
$expected = [
113+
[
114+
'uri' => '/',
115+
'translation' => __('navig.home'),
116+
],
117+
[
118+
'uri' => '',
119+
'translation' => __('navig.non-existent'),
120+
],
121+
];
122+
123+
$this->assertEquals($expected, $result);
124+
}
125+
}

0 commit comments

Comments
 (0)