Skip to content

Commit ce4628f

Browse files
committed
Merge branch 'master' into 5.6
2 parents 1e06e50 + 53aefd1 commit ce4628f

File tree

8 files changed

+127
-3
lines changed

8 files changed

+127
-3
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Provides Laravel-specific and pure PHP helper functions.
7575
- [str_lower](#str_lower)
7676
- [str_upper](#str_upper)
7777
78+
- [System](#system)
79+
- [is_windows_os](#is_windows_os)
80+
7881
- [Xml](#xml)
7982
- [xml_to_array](#xml_to_array)
8083
- [array_to_xml](#array_to_xml)
@@ -437,6 +440,18 @@ $upper = str_upper('TeSt');
437440
// TEST
438441
```
439442
443+
## System
444+
445+
#### `is_windows_os()`
446+
447+
Checks if php is running on Windows OS or not:
448+
449+
```php
450+
$isWindowsOs = is_windows_os();
451+
452+
// boolean
453+
```
454+
440455
## Xml
441456
442457
#### `xml_to_array()`

src/classes/Artisan/Command.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function runInBackground()
3131

3232
protected function composeForRunInBackground()
3333
{
34+
if (is_windows_os()) {
35+
return "start /B {$this->composeForRun()}";
36+
}
37+
3438
return "({$this->composeForRun()}) > /dev/null 2>&1 &";
3539
}
3640

src/classes/System/OS.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Illuminated\Helpers\System;
4+
5+
class OS
6+
{
7+
public static function isWindows()
8+
{
9+
return (strtoupper(substr(php_uname(), 0, 7)) === 'WINDOWS');
10+
}
11+
}

src/system.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Illuminated\Helpers\System\OS;
4+
5+
if (!function_exists('is_windows_os')) {
6+
function is_windows_os()
7+
{
8+
return OS::isWindows();
9+
}
10+
}

tests/HelperFunctions/TestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ protected function setUp()
2020
self::$functions = mock();
2121
}
2222

23+
protected function emulateLinuxOs()
24+
{
25+
self::$functions->expects()->php_uname()
26+
->andReturns('Linux localhost 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686');
27+
}
28+
29+
protected function emulateWindowsOs()
30+
{
31+
self::$functions->expects()->php_uname()
32+
->andReturns('Windows NT XN1 5.1 build 2600');
33+
}
34+
2335
protected function expectsExecWith($command)
2436
{
2537
self::$functions->expects()->exec($command);

tests/HelperFunctions/classes/Artisan/CommandTest.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ public function it_has_static_constructor_named_factory()
2828
$this->assertInstanceOf(Command::class, $command);
2929
}
3030

31-
/** @test */
31+
/**
32+
* @test
33+
* @runInSeparateProcess
34+
* @preserveGlobalState disabled
35+
*/
3236
public function it_can_run_command_in_background()
3337
{
3438
$this->expectsExecWith('(php artisan test:command) > /dev/null 2>&1 &');
@@ -38,6 +42,22 @@ public function it_can_run_command_in_background()
3842
}
3943

4044
/** @test */
45+
public function which_also_works_for_windows()
46+
{
47+
require_once 'mocks.php';
48+
49+
$this->emulateWindowsOs();
50+
$this->expectsExecWith('start /B php artisan test:command');
51+
52+
$command = Command::factory('test:command');
53+
$command->runInBackground();
54+
}
55+
56+
/**
57+
* @test
58+
* @runInSeparateProcess
59+
* @preserveGlobalState disabled
60+
*/
4161
public function run_in_background_supports_before_subcommand()
4262
{
4363
$this->expectsExecWith('(before command && php artisan test:command) > /dev/null 2>&1 &');
@@ -46,7 +66,11 @@ public function run_in_background_supports_before_subcommand()
4666
$command->runInBackground();
4767
}
4868

49-
/** @test */
69+
/**
70+
* @test
71+
* @runInSeparateProcess
72+
* @preserveGlobalState disabled
73+
*/
5074
public function run_in_background_supports_after_subcommand()
5175
{
5276
$this->expectsExecWith('(php artisan test:command && after command) > /dev/null 2>&1 &');
@@ -55,7 +79,11 @@ public function run_in_background_supports_after_subcommand()
5579
$command->runInBackground();
5680
}
5781

58-
/** @test */
82+
/**
83+
* @test
84+
* @runInSeparateProcess
85+
* @preserveGlobalState disabled
86+
*/
5987
public function run_in_background_supports_before_and_after_subcommands_together()
6088
{
6189
$this->expectsExecWith('(before && php artisan test:command && after) > /dev/null 2>&1 &');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Illuminated\Helpers\System
4+
{
5+
use Illuminated\Helpers\HelperFunctions\Tests\TestCase;
6+
7+
if (!function_exists(__NAMESPACE__ . '\php_uname')) {
8+
function php_uname()
9+
{
10+
return TestCase::$functions->php_uname();
11+
}
12+
}
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Illuminated\Helpers\System;
4+
5+
use Illuminated\Helpers\HelperFunctions\Tests\TestCase;
6+
7+
class IsWindowsOsTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_returns_false_on_non_windows_os()
11+
{
12+
$this->emulateLinuxOs();
13+
14+
$this->assertFalse(is_windows_os());
15+
}
16+
17+
/** @test */
18+
public function it_returns_true_on_windows_os()
19+
{
20+
$this->emulateWindowsOs();
21+
22+
$this->assertTrue(is_windows_os());
23+
}
24+
}
25+
26+
if (!function_exists(__NAMESPACE__ . '\php_uname')) {
27+
function php_uname()
28+
{
29+
return TestCase::$functions->php_uname();
30+
}
31+
}

0 commit comments

Comments
 (0)