Skip to content
This repository was archived by the owner on Dec 9, 2019. It is now read-only.

Commit 8598420

Browse files
committed
Valet share tests
1 parent 12bf581 commit 8598420

File tree

2 files changed

+100
-2
lines changed

2 files changed

+100
-2
lines changed

tests/Functional/FunctionalTestCase.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ class FunctionalTestCase extends TestCase
1818
*/
1919
protected function valetCommand($command, $workingDir = null)
2020
{
21-
$valet = (isset($_SERVER['REPOSITORY']) ? $_SERVER['REPOSITORY'] . '/' : '') . 'valet';
21+
return $this->exec($this->valet() . ' ' . $command, $workingDir);
22+
}
23+
24+
/**
25+
* Get valet prefix for commands.
26+
*
27+
* @return string
28+
*/
29+
protected function valet()
30+
{
31+
if (isset($_SERVER['REPOSITORY'])) {
32+
return $_SERVER['REPOSITORY'] . '/valet';
33+
}
2234

23-
return $this->exec($valet . ' ' . $command, $workingDir);
35+
return 'valet';
2436
}
2537

2638
/**
@@ -50,4 +62,25 @@ protected function exec($command, $workingDir = null)
5062

5163
return $processOutput;
5264
}
65+
66+
/**
67+
* Run a command in the background.
68+
*
69+
* @param string $command
70+
* @param null|string $workingDir
71+
* @return Process
72+
*/
73+
protected function background($command, $workingDir = null)
74+
{
75+
$process = new Process($command);
76+
77+
$process
78+
->setWorkingDirectory(
79+
is_null($workingDir) ? realpath(__DIR__ . '/../..') : $workingDir
80+
)
81+
->setTimeout(null)
82+
->start();
83+
84+
return $process;
85+
}
5386
}

tests/Functional/ShareTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
use Valet\Tests\Functional\FunctionalTestCase;
4+
5+
/**
6+
* @group functional
7+
* @group acceptance
8+
*/
9+
class ShareTest extends FunctionalTestCase
10+
{
11+
protected function setUp()
12+
{
13+
// Create filesystem structure
14+
mkdir($_SERVER['HOME'] . '/valet-site');
15+
file_put_contents($_SERVER['HOME'] . '/valet-site/index.html', 'Valet site');
16+
$this->valetCommand('link valet', $_SERVER['HOME'] . '/valet-site');
17+
}
18+
19+
protected function tearDown()
20+
{
21+
$this->valetCommand('unsecure', $_SERVER['HOME'] . '/valet-site');
22+
Configuration::prune();
23+
Filesystem::remove($_SERVER['HOME'] . '/valet-site');
24+
Filesystem::removeBrokenLinksAt(VALET_HOME_PATH . '/Sites');
25+
}
26+
27+
public function test_we_can_share_an_http_site()
28+
{
29+
// Start ngrok tunnel
30+
$ngrok = $this->background($this->valet().' share', $_SERVER['HOME'] . '/valet-site');
31+
32+
// Assert tunnel URL is reachable
33+
$tunnel = Ngrok::currentTunnelUrl();
34+
$this->assertContains('ngrok.io', $tunnel);
35+
36+
$response = \Httpful\Request::get($tunnel)->send();
37+
$this->assertEquals(200, $response->code);
38+
$this->assertContains('Valet site', $response->body);
39+
40+
$ngrok->stop();
41+
}
42+
43+
public function test_we_can_share_an_https_site()
44+
{
45+
// Secure site
46+
$this->valetCommand('secure', $_SERVER['HOME'] . '/valet-site');
47+
48+
// Start ngrok tunnel
49+
$ngrok = $this->background($this->valet().' share', $_SERVER['HOME'] . '/valet-site');
50+
51+
// Assert tunnel URL is reachable
52+
$tunnel = Ngrok::currentTunnelUrl();
53+
54+
// TODO: Refactor Ngrok class so we can retrieve https tunnel too
55+
$tunnel = str_replace('http://', 'https://', $tunnel);
56+
57+
$this->assertContains('ngrok.io', $tunnel);
58+
59+
$response = \Httpful\Request::get($tunnel)->send();
60+
$this->assertEquals(200, $response->code);
61+
$this->assertContains('Valet site', $response->body);
62+
63+
$ngrok->stop();
64+
}
65+
}

0 commit comments

Comments
 (0)