Skip to content

Commit

Permalink
Enable usage of exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrancois committed Feb 13, 2018
1 parent b935a3f commit 5dab40c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
7 changes: 7 additions & 0 deletions src/Distilleries/Expendable/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public function getAllColumnsNames()
$reverse = true;
break;

case 'sqlite':
$query = "PRAGMA table_info('" . $this->getTable()."')";
$column_name = 'name';
$reverse = true;
break;


case 'mysql':
$query = 'SHOW COLUMNS FROM ' . $this->getTable();
$column_name = 'Field';
Expand Down
20 changes: 20 additions & 0 deletions tests/ExpendableTestCase.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Illuminate\Contracts\Debug\ExceptionHandler;

abstract class ExpendableTestCase extends \Orchestra\Testbench\BrowserKit\TestCase
{

Expand Down Expand Up @@ -80,4 +82,22 @@ protected function getPackageAliases($app)
'Excel' => 'Maatwebsite\Excel\Facades\Excel',
];
}


protected function disableExceptionHandling()
{
$this->oldExceptionHandler = $this->app->make(ExceptionHandler::class);
$this->app->instance(ExceptionHandler::class, new class extends \Distilleries\Expendable\Exceptions\Handler {
public function __construct() {}
public function report(\Exception $e) {}
public function render($request, \Exception $e) {
throw $e;
}
});
}
protected function withExceptionHandling()
{
$this->app->instance(ExceptionHandler::class, $this->oldExceptionHandler);
return $this;
}
}
39 changes: 2 additions & 37 deletions tests/Http/Controllers/Backend/LanguageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,6 @@ public function testSearch()
}


public function testSearchWithException()
{
$faker = Faker\Factory::create();
$data = [
'libelle' => str_replace('\'', '', $faker->country),
'iso' => $faker->countryCode,
'not_visible' => 0,
'is_default' => 1,
'status' => 1,
];
$language = \Distilleries\Expendable\Models\Language::create($data);
$response = $this->call('POST', action('Backend\LanguageController@postSearch'), [
'ids' => [$language->id]
]);

$result = json_decode($response->getContent());
$this->assertEquals($language->id, $result[0]->id);
$this->assertEquals($language->libelle, $result[0]->libelle);

try
{
$response = $this->call('POST', action('Backend\LanguageController@postSearch'), [
'term' => $data['iso'].$data['iso'].$data['iso']
]);

$this->assertEquals(500, $response->getStatusCode());

} catch (\Exception $e)
{
$this->assertEquals('Database driver not supported: sqlite', $e->getMessage());
}


}

public function testDestroyNoId()
{

Expand Down Expand Up @@ -261,7 +226,7 @@ public function testExportError()

public function testExportCsv()
{

$this->disableExceptionHandling();
$faker = Faker\Factory::create();
$data = [
'libelle' => str_replace('\'', '', $faker->country),
Expand All @@ -270,8 +235,8 @@ public function testExportCsv()
'is_default' => 1,
'status' => 1,
];
\Distilleries\Expendable\Models\Language::create($data);

\Distilleries\Expendable\Models\Language::create($data);
\File::delete(storage_path('exports'));
$dateBegin = date('Y-m-d', time() - (24 * 60 * 60));
$dateEnd = date('Y-m-d', time() + (24 * 60 * 60));
Expand Down
2 changes: 2 additions & 0 deletions tests/Http/Controllers/Backend/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public function testPostReminder()

public function testGetResetNoToken()
{
$this->disableExceptionHandling();

try {
$this->call('GET', action('Backend\LoginController@getReset'));
} catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e) {
Expand Down
1 change: 1 addition & 0 deletions tests/Http/Controllers/Backend/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ public function testSaveProfile()

public function testSaveProfileNotAuthorize()
{
$this->disableExceptionHandling();

$faker = Faker\Factory::create();
$role = \Distilleries\Expendable\Models\Role::create([
Expand Down
3 changes: 3 additions & 0 deletions tests/Http/Controllers/Frontend/AssetControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class AssetControllerTest extends ExpendableTestCase

public function testAssetNotFound()
{
$this->disableExceptionHandling();

try {
$response = $this->call('GET', 'storage/moximanager/' . rand());
$this->assertEquals(404, $response->getStatusCode());
Expand All @@ -20,6 +22,7 @@ public function testAssetNotFound()

public function testAssetNotAllowed()
{
$this->disableExceptionHandling();

\File::makeDirectory(storage_path('other'), 0755, false, true);
copy(realpath(__DIR__ . '/../../../data/5601729.gif'), storage_path('other/5601729.gif'));
Expand Down
3 changes: 3 additions & 0 deletions tests/Models/BaseModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testGetChoice()

public function testGetAllColumnsNames()
{
$this->disableExceptionHandling();
list($data, $model) = $this->addContent();

try
Expand Down Expand Up @@ -91,6 +92,7 @@ public function testScopeBetweenUpdateWithNoResult()

public function testScopeSearchWithResult()
{
$this->disableExceptionHandling();
try
{
list($data, $model) = $this->addContent();
Expand All @@ -108,6 +110,7 @@ public function testScopeSearchWithResult()

public function testScopeSearchWithNoResult()
{
$this->disableExceptionHandling();
try
{
list($data, $model) = $this->addContent();
Expand Down

0 comments on commit 5dab40c

Please sign in to comment.