Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Linter happy about tests #1332

Merged
merged 6 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ jobs:
coverage: xdebug
tools: pecl, composer

- name: Set Up imagick & Exiftools
- name: Set Up Imagick, FFmpeg & Exiftools
run: |
sudo apt-get update
sudo apt-get --fix-broken install
sudo apt-get -y install libimage-exiftool-perl
sudo apt-get -y install ffmpeg libimage-exiftool-perl

- name: Get composer cache directory
id: composer-cache
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/PanicAttack.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function root()
{
$this->title = 'ROOT';
$this->code = 403;
$this->message = '<span class="important">This is the root directory and it MUST NOT BE PUBLICALLY ACCESSIBLE.</span><br>
$this->message = '<span class="important">This is the root directory and MUST NOT BE PUBLICLY ACCESSIBLE.</span><br>
To access Lychee, go <a href="public/">here</a>.';
$this->displaySimpleError();
}
Expand Down
5 changes: 3 additions & 2 deletions tests/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace Tests;

use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;

trait CreatesApplication
{
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
* @return Application
*/
public function createApplication()
public function createApplication(): Application
{
$app = require __DIR__ . '/../bootstrap/app.php';

Expand Down
16 changes: 13 additions & 3 deletions tests/Feature/AlbumTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature;

use App\Facades\AccessControl;
Expand All @@ -14,7 +24,7 @@ class AlbumTest extends TestCase
*
* @return void
*/
public function testAddNotLogged()
public function testAddNotLogged(): void
{
$albums_tests = new AlbumsUnitTest($this);
$albums_tests->add(null, 'test_album', 401);
Expand All @@ -29,7 +39,7 @@ public function testAddNotLogged()
$albums_tests->get('abcdefghijklmnopqrstuvwx', 404);
}

public function testAddReadLogged()
public function testAddReadLogged(): void
{
$albums_tests = new AlbumsUnitTest($this);
$session_tests = new SessionUnitTest($this);
Expand Down Expand Up @@ -123,7 +133,7 @@ public function testAddReadLogged()
$session_tests->logout();
}

public function testTrueNegative()
public function testTrueNegative(): void
{
$albums_tests = new AlbumsUnitTest($this);
$session_tests = new SessionUnitTest($this);
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Commands extends TestCase
*
* @return void
*/
public function testCommands()
public function testCommands(): void
{
$this->artisan('lychee:decode_GPS_locations')
->expectsOutput('No photos or videos require processing.')
Expand Down
16 changes: 13 additions & 3 deletions tests/Feature/DemoTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature;

use App\Models\Configs;
Expand All @@ -11,14 +21,14 @@ class DemoTest extends TestCase
* Check that the demo page is not available
* if not enabled in the advanced config.
*/
public function testDemo0()
public function testDemo0(): void
{
// save initial value
$init_config_value = Configs::get_value('gen_demo_js');

// set to 0
Configs::set('gen_demo_js', '0');
$this->assertEquals(Configs::get_value('gen_demo_js'), '0');
static::assertEquals('0', Configs::get_value('gen_demo_js'));
d7415 marked this conversation as resolved.
Show resolved Hide resolved

// check redirection
$response = $this->get('/demo');
Expand All @@ -40,7 +50,7 @@ public function testDemo1()

// set to 0
Configs::set('gen_demo_js', '1');
$this->assertEquals(Configs::get_value('gen_demo_js'), '1');
static::assertEquals('1', Configs::get_value('gen_demo_js'));

// check redirection
$response = $this->get('/demo');
Expand Down
18 changes: 13 additions & 5 deletions tests/Feature/DiagnosticsTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<?php

/** @noinspection PhpUndefinedClassInspection */
/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature;

use AccessControl;
use App\Facades\AccessControl;
use App\Models\Configs;
use Tests\TestCase;

Expand All @@ -15,7 +23,7 @@ class DiagnosticsTest extends TestCase
*
* @return void
*/
public function testDiagnostics()
public function testDiagnostics(): void
{
$response = $this->get('/Diagnostics');
$response->assertOk(); // code 200 something
Expand All @@ -25,15 +33,15 @@ public function testDiagnostics()
$response = $this->get('/Diagnostics');
$response->assertOk(); // code 200 something

Configs::where('key', '=', 'lossless_optimization')->update(['value' => null]);
Configs::query()->where('key', '=', 'lossless_optimization')->update(['value' => null]);

$response = $this->postJson('/api/Diagnostics::get');
$response->assertOk(); // code 200 something too

$response = $this->postJson('/api/Diagnostics::getSize');
$response->assertOk(); // code 200 something too

Configs::where('key', '=', 'lossless_optimization')->update(['value' => '1']);
Configs::query()->where('key', '=', 'lossless_optimization')->update(['value' => '1']);

AccessControl::logout();
}
Expand Down
14 changes: 12 additions & 2 deletions tests/Feature/FrameTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature;

use App\Models\Configs;
Expand All @@ -14,7 +24,7 @@ public function testFrame0()

// set to 0
Configs::set('Mod_Frame', '0');
$this->assertEquals(Configs::get_value('Mod_Frame'), '0');
static::assertEquals('0', Configs::get_value('Mod_Frame'));

// check redirection
$response = $this->get('/frame');
Expand All @@ -40,7 +50,7 @@ public function testFrame1()

// set to 1
Configs::set('Mod_Frame', '1');
$this->assertEquals(Configs::get_value('Mod_Frame'), '1');
static::assertEquals('1', Configs::get_value('Mod_Frame'));

// check no redirection
$response = $this->get('/frame');
Expand Down
53 changes: 25 additions & 28 deletions tests/Feature/GeoDataTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature;

use App\Facades\AccessControl;
use App\Models\Configs;
use Carbon\Carbon;
use Illuminate\Http\UploadedFile;
use Tests\Feature\Lib\AlbumsUnitTest;
use Tests\Feature\Lib\PhotosUnitTest;
use Tests\TestCase;
Expand All @@ -15,29 +24,17 @@ class GeoDataTest extends TestCase
/**
* @return void
*/
public function testGeo()
public function testGeo(): void
{
$photos_tests = new PhotosUnitTest($this);
$albums_tests = new AlbumsUnitTest($this);

AccessControl::log_as_id(0);

/*
* Make a copy of the image because import deletes the file, and we want to be
* able to use the test on a local machine and not just in CI.
*/
copy('tests/Samples/mongolia.jpeg', 'public/uploads/import/mongolia.jpeg');

$file = new UploadedFile(
'public/uploads/import/mongolia.jpeg',
'mongolia.jpeg',
'image/jpeg',
null,
true
$id = $photos_tests->upload(
TestCase::createUploadedFile(TestCase::SAMPLE_FILE_MONGOLIA_IMAGE)
);

$id = $photos_tests->upload($file);

$response = $photos_tests->get($id);
$photos_tests->see_in_unsorted($id);
/*
Expand Down Expand Up @@ -96,40 +93,40 @@ public function testGeo()
$photos_tests->dont_see_in_unsorted($id);
$response = $albums_tests->get($albumID);
$responseObj = json_decode($response->getContent());
$this->assertCount(1, $responseObj->photos);
$this->assertEquals($id, $responseObj->photos[0]->id);
static::assertCount(1, $responseObj->photos);
static::assertEquals($id, $responseObj->photos[0]->id);

// now we test position Data
// save initial value
$map_display_value = Configs::get_value('map_display');

// set to 0
Configs::set('map_display', '0');
$this->assertEquals('0', Configs::get_value('map_display'));
static::assertEquals('0', Configs::get_value('map_display'));
$albums_tests->AlbumsGetPositionDataFull(); // we need to fix this

// set to 1
Configs::set('map_display', '1');
$this->assertEquals('1', Configs::get_value('map_display'));
static::assertEquals('1', Configs::get_value('map_display'));
$response = $albums_tests->AlbumsGetPositionDataFull();
$responseObj = json_decode($response->getContent());
$this->assertObjectHasAttribute('photos', $responseObj);
$this->assertCount(1, $responseObj->photos);
$this->assertEquals($id, $responseObj->photos[0]->id);
static::assertObjectHasAttribute('photos', $responseObj);
static::assertCount(1, $responseObj->photos);
static::assertEquals($id, $responseObj->photos[0]->id);

// set to 0
Configs::set('map_display', '0');
$this->assertEquals('0', Configs::get_value('map_display'));
static::assertEquals('0', Configs::get_value('map_display'));
$albums_tests->AlbumGetPositionDataFull($albumID); // we need to fix this

// set to 1
Configs::set('map_display', '1');
$this->assertEquals('1', Configs::get_value('map_display'));
static::assertEquals('1', Configs::get_value('map_display'));
$response = $albums_tests->AlbumGetPositionDataFull($albumID);
$responseObj = json_decode($response->getContent());
$this->assertObjectHasAttribute('photos', $responseObj);
$this->assertCount(1, $responseObj->photos);
$this->assertEquals($id, $responseObj->photos[0]->id);
static::assertObjectHasAttribute('photos', $responseObj);
static::assertCount(1, $responseObj->photos);
static::assertEquals($id, $responseObj->photos[0]->id);

$photos_tests->delete([$id]);
$albums_tests->delete([$albumID]);
Expand Down
18 changes: 14 additions & 4 deletions tests/Feature/IndexTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?php

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Feature;

use App\Facades\AccessControl;
Expand All @@ -13,7 +23,7 @@ class IndexTest extends TestCase
*
* @return void
*/
public function testHome()
public function testHome(): void
{
/**
* check if we can actually get a nice answer.
Expand All @@ -30,15 +40,15 @@ public function testHome()
*
* @return void
*/
public function testPhpInfo()
public function testPhpInfo(): void
{
AccessControl::logout();
// we don't want a non admin to access this
$response = $this->get('/phpinfo');
$response->assertForbidden();
}

public function testLandingPage()
public function testLandingPage(): void
{
$landing_on_off = Configs::get_value('landing_page_enable', '0');
Configs::set('landing_page_enable', 1);
Expand All @@ -48,7 +58,7 @@ public function testLandingPage()
$response->assertViewIs('landing');

$response = $this->get('/gallery');
$response->assertOk(200);
$response->assertOk();
$response->assertViewIs('gallery');

Configs::set('landing_page_enable', $landing_on_off);
Expand Down
Loading