Skip to content

Commit f4ce53e

Browse files
authored
Travis with multiple Laravel versions (#38)
* test travis * replace before_script by before_install * remove mockery * update travis * updates * dispatcher updates * updates * updates * updates * updates * updates
1 parent d4e1e51 commit f4ce53e

File tree

8 files changed

+125
-35
lines changed

8 files changed

+125
-35
lines changed

.travis.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
11
language: php
22

3+
cache:
4+
directories:
5+
- $HOME/.cache/pip
6+
- $HOME/.composer/cache/files
7+
38
php:
49
- 7.0
510
- 7.1
611
- 7.2
712
- 7.3
813

9-
before_script:
14+
env:
15+
- ILLUMINATE_VERSION=5.1.* PHPUNIT_VERSION=~4.0
16+
- ILLUMINATE_VERSION=5.2.* PHPUNIT_VERSION=~4.0
17+
- ILLUMINATE_VERSION=5.3.* PHPUNIT_VERSION=~5.0
18+
- ILLUMINATE_VERSION=5.4.* PHPUNIT_VERSION=~5.7
19+
- ILLUMINATE_VERSION=5.5.* PHPUNIT_VERSION=~6.0
20+
- ILLUMINATE_VERSION=5.6.* PHPUNIT_VERSION=~7.0
21+
- ILLUMINATE_VERSION=5.7.* PHPUNIT_VERSION=~7.0
22+
- ILLUMINATE_VERSION=5.8.* PHPUNIT_VERSION=^7.5
23+
24+
matrix:
25+
exclude:
26+
# 5.5 & 7.0
27+
- php: 7.0
28+
env: ILLUMINATE_VERSION=5.6.* PHPUNIT_VERSION=~7.0
29+
- php: 7.0
30+
env: ILLUMINATE_VERSION=5.7.* PHPUNIT_VERSION=~7.0
31+
- php: 7.0
32+
env: ILLUMINATE_VERSION=5.8.* PHPUNIT_VERSION=^7.5
33+
# 5.4 & 7.1
34+
- php: 7.1
35+
env: ILLUMINATE_VERSION=5.1.* PHPUNIT_VERSION=~4.0
36+
- php: 7.1
37+
env: ILLUMINATE_VERSION=5.2.* PHPUNIT_VERSION=~4.0
38+
- php: 7.1
39+
env: ILLUMINATE_VERSION=5.3.* PHPUNIT_VERSION=~5.0
40+
41+
before_install:
1042
- travis_retry composer self-update
11-
- travis_retry composer install --prefer-source --no-interaction --dev
43+
- composer require "illuminate/support:${ILLUMINATE_VERSION}" --no-update --prefer-dist
44+
- composer require "orchestra/testbench:${ILLUMINATE_VERSION/5\./3\.}" --no-update --prefer-dist
45+
- composer require "phpunit/phpunit:${PHPUNIT_VERSION}" --no-update --prefer-dist
46+
47+
install: travis_retry composer install --no-interaction --prefer-dist
1248

1349
script: vendor/bin/phpunit

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "~6.0",
19-
"mockery/mockery": "^0.9.4",
20-
"orchestra/testbench": "^3.5"
19+
"orchestra/testbench": "^3.5",
20+
"mockery/mockery": "^1.2"
2121
},
2222
"autoload": {
2323
"psr-0": {

src/Understand/UnderstandLaravel5/FieldProvider.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,29 @@ protected function getPostDataArray()
417417
return null;
418418
}
419419

420-
if ( ! $this->request->request instanceof \IteratorAggregate)
420+
$source = null;
421+
422+
if (method_exists($this->request, 'json') && method_exists($this->request, 'isJson') && $this->request->isJson())
421423
{
422-
return null;
424+
$source = $this->request->json();
425+
}
426+
else if ($this->request->request instanceof \IteratorAggregate)
427+
{
428+
$source = $this->request->request;
429+
}
430+
else
431+
{
432+
return;
433+
}
434+
435+
if ( ! $source)
436+
{
437+
return;
423438
}
424439

425440
$postData = [];
426441

427-
foreach($this->request->request as $key => $value)
442+
foreach($source as $key => $value)
428443
{
429444
try
430445
{

tests/EventListenerTest.php

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3+
use Illuminate\Foundation\Application;
34
use Illuminate\Queue\Events\JobProcessing;
5+
use Illuminate\Support\Str;
46
use Understand\UnderstandLaravel5\Logger;
57
use Understand\UnderstandLaravel5\Handlers\CallbackHandler;
68

@@ -17,7 +19,7 @@ protected function getPackageProviders($app)
1719
{
1820
return ['Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider'];
1921
}
20-
22+
2123
/**
2224
* Test event listener
2325
*
@@ -57,17 +59,26 @@ public function testEventListener()
5759
*/
5860
public function testRegenerateToken()
5961
{
60-
$payload = 'test';
61-
$connectionName = 'sync';
62-
$queue = 'sync';
63-
6462
$initialToken = $this->app['understand.tokenProvider']->getToken();
6563

6664
$this->assertEquals($initialToken, $this->app['understand.tokenProvider']->getToken());
6765

68-
$job = new \Illuminate\Queue\Jobs\SyncJob($this->app, $payload, $connectionName, $queue);
66+
$event = 'illuminate.queue.after';
67+
68+
if (class_exists('Illuminate\Queue\Events\JobProcessing'))
69+
{
70+
$job = new \Illuminate\Queue\Jobs\SyncJob($this->app, 'test', 'sync', 'sync');
71+
$event = new JobProcessing('sync', $job, ['only 5.2 requires the third parameter']);
72+
}
6973

70-
$this->app['events']->dispatch(new JobProcessing($connectionName, $job));
74+
if (method_exists($this->app['events'], 'dispatch'))
75+
{
76+
$this->app['events']->dispatch($event);
77+
}
78+
else
79+
{
80+
$this->app['events']->fire($event);
81+
}
7182

7283
$this->assertNotEmpty($initialToken);
7384
$this->assertNotEquals($initialToken, $this->app['understand.tokenProvider']->getToken());
@@ -80,16 +91,26 @@ public function testRegenerateToken()
8091
*/
8192
public function testDataCollectorResetsToken()
8293
{
83-
$payload = 'test';
84-
$connectionName = 'sync';
85-
$queue = 'sync';
86-
8794
$this->app['understand.dataCollector']->setInArray('test', 1);
8895

8996
$this->assertEquals([1], $this->app['understand.dataCollector']->getByKey('test'));
9097

91-
$job = new \Illuminate\Queue\Jobs\SyncJob($this->app, $payload, $connectionName, $queue);
92-
$this->app['events']->dispatch(new JobProcessing($connectionName, $job));
98+
$event = 'illuminate.queue.after';
99+
100+
if (class_exists('Illuminate\Queue\Events\JobProcessing'))
101+
{
102+
$job = new \Illuminate\Queue\Jobs\SyncJob($this->app, 'test', 'sync', 'sync');
103+
$event = new JobProcessing('sync', $job, ['only 5.2 requires the third parameter']);
104+
}
105+
106+
if (method_exists($this->app['events'], 'dispatch'))
107+
{
108+
$this->app['events']->dispatch($event);
109+
}
110+
else
111+
{
112+
$this->app['events']->fire($event);
113+
}
93114

94115
$this->assertEmpty($this->app['understand.dataCollector']->getByKey('test'));
95116
}
@@ -259,7 +280,7 @@ public function testLoggerMessageBoolean()
259280
$this->assertSame($called, 1);
260281
$this->assertTrue($messageSame);
261282
}
262-
283+
263284
/**
264285
* @return void
265286
*/

tests/ExceptionEncoderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
3+
use Orchestra\Testbench\TestCase;
44

55
class ExceptionEncoderTest extends TestCase
66
{

tests/FieldProviderTest.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Illuminate\Foundation\AliasLoader;
4+
use Illuminate\Support\Str;
45

56
class FieldProviderTest extends Orchestra\Testbench\TestCase
67
{
@@ -33,39 +34,39 @@ public function testExtend()
3334
public function testLaravelAuth()
3435
{
3536
$userId = 23452345;
36-
37+
3738
\Illuminate\Support\Facades\Auth::shouldReceive('id')->once()->andReturn($userId);
38-
39+
3940
$currentUserId = $this->app['understand.fieldProvider']->getUserId();
40-
41+
4142
$this->assertSame($userId, $currentUserId);
4243
}
43-
44+
4445
public function testSentinelGetUser()
4546
{
4647
$loader = AliasLoader::getInstance();
4748
$loader->alias('Sentinel', '\Illuminate\Support\Facades\Auth');
48-
49+
4950
$user = new stdClass();
5051
$user->id = 423523;
51-
52+
5253
\Illuminate\Support\Facades\Auth::shouldReceive('getUser')->once()->andReturn($user);
53-
54+
5455
$currentUserId = $this->app['understand.fieldProvider']->getUserId();
5556

5657
$this->assertSame($user->id, $currentUserId);
5758
}
58-
59+
5960
public function testSentryGetUser()
6061
{
6162
$loader = AliasLoader::getInstance();
6263
$loader->alias('Sentry', '\Illuminate\Support\Facades\Auth');
63-
64+
6465
$user = new stdClass();
6566
$user->id = 545;
66-
67+
6768
\Illuminate\Support\Facades\Auth::shouldReceive('getUser')->once()->andReturn($user);
68-
69+
6970
$currentUserId = $this->app['understand.fieldProvider']->getUserId();
7071

7172
$this->assertSame($user->id, $currentUserId);
@@ -117,6 +118,8 @@ public function testEnableQueryBindings()
117118

118119
public function testGetServerIp()
119120
{
121+
\Illuminate\Support\Facades\Route::get('/', function() {});
122+
120123
$this->call('GET', '/', [], [], [], ['SERVER_ADDR' => '127.0 0.1']);
121124

122125
$ip = $this->app['understand.fieldProvider']->getServerIp();
@@ -126,6 +129,8 @@ public function testGetServerIp()
126129

127130
public function testQueryString()
128131
{
132+
\Illuminate\Support\Facades\Route::get('/test', function() {});
133+
129134
$this->call('GET', '/test?query=123&password=1234');
130135

131136
$queryString = $this->app['understand.fieldProvider']->getQueryStringArray();
@@ -136,6 +141,8 @@ public function testQueryString()
136141

137142
public function testPostRequestParameters()
138143
{
144+
\Illuminate\Support\Facades\Route::post('/', function() {});
145+
139146
$this->call('POST', '/', ['test' => 'a', 'password' => 'b']);
140147

141148
$postData = $this->app['understand.fieldProvider']->getPostDataArray();
@@ -146,6 +153,13 @@ public function testPostRequestParameters()
146153

147154
public function testJsonRequest()
148155
{
156+
if ( ! method_exists($this, 'json'))
157+
{
158+
return $this->markTestSkipped('The test base class does not support json requests');
159+
}
160+
161+
\Illuminate\Support\Facades\Route::post('/', function() {});
162+
149163
$this->json('POST', '/', ['test' => 'b', 'password' => 'test']);
150164

151165
$jsonData = $this->app['understand.fieldProvider']->getPostDataArray();
@@ -156,6 +170,8 @@ public function testJsonRequest()
156170

157171
public function testQueryStringDisabled()
158172
{
173+
\Illuminate\Support\Facades\Route::get('/test', function() {});
174+
159175
$this->app['config']->set('understand-laravel.query_string_enabled', false);
160176

161177
$this->call('GET', '/test?query=123&password=1234');
@@ -167,6 +183,8 @@ public function testQueryStringDisabled()
167183

168184
public function testPostRequestParametersDisabled()
169185
{
186+
\Illuminate\Support\Facades\Route::post('/', function() {});
187+
170188
$this->app['config']->set('understand-laravel.post_data_enabled', false);
171189

172190
$this->call('POST', '/', ['test' => 'a', 'password' => 'b']);

tests/TestFileReaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Understand\UnderstandLaravel5\ExceptionEncoder;
4-
use PHPUnit\Framework\TestCase;
4+
use Orchestra\Testbench\TestCase;
55

66
class TestFileReaderTest extends TestCase
77
{

tests/TokenProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
3+
use Orchestra\Testbench\TestCase;
44

55
class TokenProviderTest extends TestCase
66
{

0 commit comments

Comments
 (0)