Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit 9825b5c

Browse files
author
Jose Fonseca
committed
improve coverage.
1 parent a4c2cc1 commit 9825b5c

File tree

4 files changed

+40
-93
lines changed

4 files changed

+40
-93
lines changed

app/Http/Controllers/Api/Assets/UploadFileController.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,12 @@ protected function storeInFileSystem(array $attributes)
156156
/**
157157
* @param $url
158158
* @return \Psr\Http\Message\ResponseInterface
159+
* @throws \GuzzleHttp\Exception\GuzzleException
159160
*/
160161
protected function callFileUrl($url)
161162
{
162163
try {
163-
$response = $this->client->get($url);
164-
if ($response->getStatusCode() != 200) {
165-
throw new StoreResourceFailedException('Validation Error', [
166-
'url' => 'The url seems unreachable',
167-
]);
168-
}
169-
170-
return $response;
164+
return $this->client->get($url);
171165
} catch (TransferException $e) {
172166
throw new StoreResourceFailedException('Validation Error', [
173167
'url' => 'The url seems to be unreachable: '.$e->getCode(),

app/Services/Installation/InstallAppCommand.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

phpunit.xml

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4-
backupGlobals="false"
5-
backupStaticAttributes="false"
6-
bootstrap="vendor/autoload.php"
7-
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
processIsolation="false"
12-
stopOnFailure="false">
13-
<testsuites>
14-
<testsuite name="Unit">
15-
<directory suffix="Test.php">./tests/Unit</directory>
16-
</testsuite>
17-
18-
<testsuite name="Feature">
19-
<directory suffix="Test.php">./tests/Feature</directory>
20-
</testsuite>
21-
</testsuites>
22-
<filter>
23-
<whitelist processUncoveredFilesFromWhitelist="true">
24-
<directory suffix=".php">./app</directory>
25-
</whitelist>
26-
</filter>
27-
<php>
28-
<server name="APP_ENV" value="testing"/>
29-
<server name="BCRYPT_ROUNDS" value="4"/>
30-
<server name="CACHE_DRIVER" value="array"/>
31-
<server name="MAIL_DRIVER" value="array"/>
32-
<server name="QUEUE_CONNECTION" value="sync"/>
33-
<server name="SESSION_DRIVER" value="array"/>
34-
<env name="DB_CONNECTION" value="sqlite"/>
35-
<env name="DB_DATABASE" value=":memory:"/>
36-
<env name="API_VERSION" value="v1"/>
37-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">./app</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Unit">
10+
<directory suffix="Test.php">./tests/Unit</directory>
11+
</testsuite>
12+
<testsuite name="Feature">
13+
<directory suffix="Test.php">./tests/Feature</directory>
14+
</testsuite>
15+
</testsuites>
16+
<php>
17+
<server name="APP_ENV" value="testing"/>
18+
<server name="BCRYPT_ROUNDS" value="4"/>
19+
<server name="CACHE_DRIVER" value="array"/>
20+
<server name="MAIL_DRIVER" value="array"/>
21+
<server name="QUEUE_CONNECTION" value="sync"/>
22+
<server name="SESSION_DRIVER" value="array"/>
23+
<env name="DB_CONNECTION" value="sqlite"/>
24+
<env name="DB_DATABASE" value=":memory:"/>
25+
<env name="API_VERSION" value="v1"/>
26+
</php>
3827
</phpunit>

tests/Feature/Assets/UploadImageTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,17 @@ function test_it_validates_mime_on_url()
140140
$this->assertArrayHasKey('Content-Type', $jsonResponse['errors']);
141141

142142
}
143+
144+
function test_it_validates_url()
145+
{
146+
Passport::actingAs(
147+
factory(User::class)->create()
148+
);
149+
$response = $this->json('POST', 'api/assets', [
150+
'url' => 'http://somedomain.com/350x150'
151+
]);
152+
$jsonResponse = json_decode($response->getContent(), true);
153+
$this->assertEquals(422, $response->getStatusCode());
154+
$this->assertArrayHasKey('Content-Type', $jsonResponse['errors']);
155+
}
143156
}

0 commit comments

Comments
 (0)