Rename the tests to pass phpcs checks

This commit is contained in:
Jonny Barnes 2021-03-17 18:38:18 +00:00
parent 3946e9aac4
commit d5bbed1eac
52 changed files with 1329 additions and 1062 deletions

View file

@ -1,16 +1,19 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use App\Jobs\AddClientToDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class AddClientToDatabaseJobTest extends TestCase
{
use DatabaseTransactions;
public function test_job_adds_client()
/** @test */
public function clientIsAddedToDatabaseByJob(): void
{
$job = new AddClientToDatabase('https://example.org/client');
$job->handle();

View file

@ -1,14 +1,16 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use App\Jobs\DownloadWebMention;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use App\Jobs\DownloadWebMention;
use GuzzleHttp\Handler\MockHandler;
use Illuminate\FileSystem\FileSystem;
use Tests\TestCase;
class DownloadWebMentionJobTest extends TestCase
{
@ -21,15 +23,16 @@ class DownloadWebMentionJobTest extends TestCase
parent::tearDown();
}
public function test_the_job_saves_html()
/** @test */
public function htmlIsSavedByJob(): void
{
$this->assertFileDoesNotExist(storage_path('HTML/https'));
$source = 'https://example.org/reply/1';
$html = <<<HTML
<div class="h-entry">
<a class="u-like-of" href=""></a>
</div>
HTML;
<div class="h-entry">
<a class="u-like-of" href=""></a>
</div>
HTML;
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
$mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], $html),
@ -48,21 +51,22 @@ HTML;
$this->assertFileDoesNotExist(storage_path('HTML/https/example.org/reply') . '/1.' . date('Y-m-d') . '.backup');
}
public function test_the_job_saves_html_and_backup()
/** @test */
public function htmlAndBackupSavedByJob(): void
{
$this->assertFileDoesNotExist(storage_path('HTML/https'));
$source = 'https://example.org/reply/1';
$html = <<<HTML
<div class="h-entry">
<a class="u-like-of" href=""></a>
</div>
HTML;
<div class="h-entry">
<a class="u-like-of" href=""></a>
</div>
HTML;
$html2 = <<<HTML
<div class="h-entry">
<a class="u-like-of" href=""></a>
<a class="u-repost-of" href=""></a>
</div>
HTML;
<div class="h-entry">
<a class="u-like-of" href=""></a>
<a class="u-repost-of" href=""></a>
</div>
HTML;
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
$html2 = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html2);
$mock = new MockHandler([
@ -82,15 +86,16 @@ HTML;
$this->assertFileExists(storage_path('HTML/https/example.org/reply') . '/1.' . date('Y-m-d') . '.backup');
}
public function test_an_index_html_file()
/** @test */
public function indexHtmlFileIsSavedByJobForUrlsEndingWithSlash(): void
{
$this->assertFileDoesNotExist(storage_path('HTML/https'));
$source = 'https://example.org/reply-one/';
$html = <<<HTML
<div class="h-entry">
<a class="u-like-of" href=""></a>
</div>
HTML;
<div class="h-entry">
<a class="u-like-of" href=""></a>
</div>
HTML;
$html = str_replace('href=""', 'href="' . config('app.url') . '/notes/A"', $html);
$mock = new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], $html),

View file

@ -1,24 +1,23 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use Ramsey\Uuid\Uuid;
use GuzzleHttp\Client;
use App\Models\Bookmark;
use GuzzleHttp\HandlerStack;
use App\Jobs\ProcessBookmark;
use GuzzleHttp\Psr7\Response;
use App\Services\BookmarkService;
use GuzzleHttp\Handler\MockHandler;
use App\Exceptions\InternetArchiveException;
use App\Jobs\ProcessBookmark;
use App\Models\Bookmark;
use App\Services\BookmarkService;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Ramsey\Uuid\Uuid;
use Tests\TestCase;
class ProcessBookmarkJobTest extends TestCase
{
use DatabaseTransactions;
public function test_screenshot_and_archive_link_are_saved()
/** @test */
public function screenshotAndArchiveLinkAreSavedByJob(): void
{
$bookmark = Bookmark::find(1);
$uuid = Uuid::uuid4();
@ -38,7 +37,8 @@ class ProcessBookmarkJobTest extends TestCase
]);
}
public function test_exception_casesu_null_value_for_archive_link()
/** @test */
public function archiveLinkSavedAsNullWhenExceptionThrown(): void
{
$bookmark = Bookmark::find(1);
$uuid = Uuid::uuid4();
@ -46,7 +46,7 @@ class ProcessBookmarkJobTest extends TestCase
$service->method('saveScreenshot')
->willReturn($uuid->toString());
$service->method('getArchiveLink')
->will($this->throwException(new InternetArchiveException));
->will($this->throwException(new InternetArchiveException()));
$this->app->instance(BookmarkService::class, $service);
$job = new ProcessBookmark($bookmark);

View file

@ -1,15 +1,18 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Storage;
use Tests\TestCase;
use App\Jobs\ProcessMedia;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\ImageManager;
use Tests\TestCase;
class ProcessMediaJobTest extends TestCase
{
public function test_job_does_nothing_to_non_image()
/** @test */
public function nonMediaFilesAreNotSaved(): void
{
Storage::fake('s3');
$manager = app()->make(ImageManager::class);
@ -20,18 +23,20 @@ class ProcessMediaJobTest extends TestCase
$this->assertFalse(file_exists(storage_path('app') . '/file.txt'));
}
public function test_job_does_nothing_to_small_images()
/** @test */
public function smallImagesAreNotResized(): void
{
Storage::fake('s3');
$manager = app()->make(ImageManager::class);
Storage::disk('local')->put('aaron.png', file_get_contents(__DIR__.'/../../aaron.png'));
Storage::disk('local')->put('aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
$job = new ProcessMedia('aaron.png');
$job->handle($manager);
$this->assertFalse(file_exists(storage_path('app') . '/aaron.png'));
}
public function test_large_images_have_smaller_files_created()
/** @test */
public function largeImagesHaveSmallerImagesCreated(): void
{
$manager = app()->make(ImageManager::class);
Storage::disk('local')->put('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));

View file

@ -1,21 +1,23 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use App\Exceptions\RemoteContentNotFoundException;
use App\Jobs\ProcessWebMention;
use App\Jobs\SaveProfileImage;
use App\Models\Note;
use GuzzleHttp\Client;
use App\Models\WebMention;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use App\Jobs\SaveProfileImage;
use App\Jobs\ProcessWebMention;
use GuzzleHttp\Handler\MockHandler;
use Illuminate\FileSystem\FileSystem;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Queue;
use Jonnybarnes\WebmentionsParser\Parser;
use App\Exceptions\RemoteContentNotFoundException;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class ProcessWebMentionJobTest extends TestCase
{
@ -30,7 +32,8 @@ class ProcessWebMentionJobTest extends TestCase
parent::tearDown();
}
public function test_for_exception_from_failure_to_get_webmention()
/** @test */
public function failureGettingWebmentionThrowsAnException(): void
{
$this->expectException(RemoteContentNotFoundException::class);
@ -48,17 +51,18 @@ class ProcessWebMentionJobTest extends TestCase
$job->handle($parser, $client);
}
public function test_a_new_webmention_gets_saved()
/** @test */
public function newWebmentionGetsSavedByJob(): void
{
Queue::fake();
$parser = new Parser();
$html = <<<HTML
<div class="h-entry">
I liked <a class="u-like-of" href="/notes/1">a note</a>.
</div>
HTML;
<div class="h-entry">
I liked <a class="u-like-of" href="/notes/1">a note</a>.
</div>
HTML;
$html = str_replace('href="', 'href="' . config('app.url'), $html);
$mock = new MockHandler([
new Response(200, [], $html),
@ -79,18 +83,19 @@ HTML;
]);
}
public function test_existing_webmention_gets_updated()
/** @test */
public function existingWebmentionGetsUpdatedByJob(): void
{
Queue::fake();
$parser = new Parser();
$html = <<<HTML
<div class="h-entry">
<p>In reply to <a class="u-in-reply-to" href="/notes/E">a note</a></p>
<div class="e-content">Updated reply</div>
</div>
HTML;
<div class="h-entry">
<p>In reply to <a class="u-in-reply-to" href="/notes/E">a note</a></p>
<div class="e-content">Updated reply</div>
</div>
HTML;
$html = str_replace('href="', 'href="' . config('app.url'), $html);
$mock = new MockHandler([
new Response(200, [], $html),
@ -108,20 +113,22 @@ HTML;
$this->assertDatabaseHas('webmentions', [
'source' => $source,
'type' => 'in-reply-to',
// phpcs:ignore Generic.Files.LineLength.TooLong
'mf2' => '{"rels": [], "items": [{"type": ["h-entry"], "properties": {"content": [{"html": "Updated reply", "value": "Updated reply"}], "in-reply-to": ["' . config('app.url') . '/notes/E"]}}], "rel-urls": []}',
]);
}
public function test_webmention_reply_gets_deleted()
/** @test */
public function webmentionReplyGetsDeletedWhenReplyToValueChanges(): void
{
$parser = new Parser();
$html = <<<HTML
<div class="h-entry">
<p>In reply to <a class="u-in-reply-to" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">Replying to someone else</div>
</div>
HTML;
<div class="h-entry">
<p>In reply to <a class="u-in-reply-to" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">Replying to someone else</div>
</div>
HTML;
$mock = new MockHandler([
new Response(200, [], $html),
]);
@ -148,16 +155,17 @@ HTML;
]);
}
public function test_webmention_like_gets_deleted()
/** @test */
public function webmentionLikeGetsDeletedWhenLikeOfValueChanges(): void
{
$parser = new Parser();
$html = <<<HTML
<div class="h-entry">
<p>In reply to <a class="u-like-of" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">I like someone else now</div>
</div>
HTML;
<div class="h-entry">
<p>In reply to <a class="u-like-of" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">I like someone else now</div>
</div>
HTML;
$mock = new MockHandler([
new Response(200, [], $html),
]);
@ -184,16 +192,17 @@ HTML;
]);
}
public function test_webmention_repost_gets_deleted()
/** @test */
public function webmentionRepostGetsDeletedWhenRepostOfValueChanges(): void
{
$parser = new Parser();
$html = <<<HTML
<div class="h-entry">
<p>In reply to <a class="u-repost-of" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">Reposting someone else</div>
</div>
HTML;
<div class="h-entry">
<p>In reply to <a class="u-repost-of" href="https://other.com/notes/E">a note</a></p>
<div class="e-content">Reposting someone else</div>
</div>
HTML;
$mock = new MockHandler([
new Response(200, [], $html),
]);

View file

@ -1,16 +1,17 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use App\Jobs\SaveProfileImage;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use App\Jobs\SaveProfileImage;
use GuzzleHttp\Handler\MockHandler;
use Jonnybarnes\WebmentionsParser\Authorship;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Jonnybarnes\WebmentionsParser\Exceptions\AuthorshipParserException;
use Tests\TestCase;
class SaveProfileImageJobTest extends TestCase
{
@ -22,18 +23,21 @@ class SaveProfileImageJobTest extends TestCase
}
parent::tearDown();
}
public function test_authorship_algo_exception_return_null()
/** @test */
public function authorshipAlgorithmReturnsNullOnException(): void
{
$mf = ['items' => []];
$authorship = $this->createMock(Authorship::class);
$authorship->method('findAuthor')
->will($this->throwException(new AuthorshipParserException));
->will($this->throwException(new AuthorshipParserException()));
$job = new SaveProfileImage($mf);
$this->assertNull($job->handle($authorship));
}
public function test_we_dont_process_twitter_images()
/** @test */
public function weDoNotProcessTwitterImages(): void
{
$mf = ['items' => []];
$author = [
@ -50,7 +54,8 @@ class SaveProfileImageJobTest extends TestCase
$this->assertNull($job->handle($authorship));
}
public function test_saving_of_remote_image()
/** @test */
public function remoteAuthorImagesAreSavedLocally(): void
{
$mock = new MockHandler([
new Response(200, ['Content-Type' => 'image/jpeg'], 'fake jpeg image'),
@ -74,7 +79,8 @@ class SaveProfileImageJobTest extends TestCase
$this->assertFileExists(public_path() . '/assets/profile-images/example.org/image');
}
public function test_copying_of_local_image()
/** @test */
public function localDefaultAuthorImageIsUsedAsFallback(): void
{
$mock = new MockHandler([
new Response(404),

View file

@ -1,19 +1,21 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use App\Jobs\SendWebMentions;
use App\Models\Note;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use App\Jobs\SendWebMentions;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use Illuminate\Foundation\Testing\RefreshDatabase;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Tests\TestCase;
class SendWebMentionJobTest extends TestCase
{
public function test_dicover_endoint_method_on_self()
/** @test */
public function discoverWebmentionEndpointOnOwnDomain(): void
{
$note = new Note();
$job = new SendWebMentions($note);
@ -21,7 +23,8 @@ class SendWebMentionJobTest extends TestCase
$this->assertNull($job->discoverWebmentionEndpoint('/notes/tagged/test'));
}
public function test_discover_endpoint_gets_link_from_headers()
/** @test */
public function discoverWebmentionEndpointFromHeaderLinks(): void
{
$url = 'https://example.org/webmention';
$mock = new MockHandler([
@ -35,7 +38,8 @@ class SendWebMentionJobTest extends TestCase
$this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org'));
}
public function test_discover_endpoint_correctly_parses_html()
/** @test */
public function discoverWebmentionEndpointFromHtmlLinkTags(): void
{
$html = '<link rel="webmention" href="https://example.org/webmention">';
$mock = new MockHandler([
@ -52,7 +56,8 @@ class SendWebMentionJobTest extends TestCase
);
}
public function test_discover_endpoint_correctly_parses_html_legacy()
/** @test */
public function discoverWebmentionEndpointFromLegacyHtmlMarkup(): void
{
$html = '<link rel="http://webmention.org/" href="https://example.org/webmention">';
$mock = new MockHandler([
@ -69,13 +74,15 @@ class SendWebMentionJobTest extends TestCase
);
}
public function test_empty_note_does_nothing()
/** @test */
public function ensureEmptyNoteDoesNotTriggerAnyActions(): void
{
$job = new SendWebMentions(new Note());
$this->assertNull($job->handle());
}
public function test_resolve_uri()
/** @test */
public function weResolveRelativeUris(): void
{
$uri = '/blog/post';
$base = 'https://example.org/';
@ -83,7 +90,8 @@ class SendWebMentionJobTest extends TestCase
$this->assertEquals('https://example.org/blog/post', $job->resolveUri($uri, $base));
}
public function test_the_job()
/** @test */
public function weSendAWebmentionForANote(): void
{
$html = '<link rel="http://webmention.org/" href="https://example.org/webmention">';
$mock = new MockHandler([
@ -98,6 +106,7 @@ class SendWebMentionJobTest extends TestCase
$note->note = 'Hi [Aaron](https://aaronparecki.com)';
$note->save();
$job = new SendWebMentions($note);
$this->assertNull($job->handle());
$job->handle();
$this->assertTrue(true);
}
}

View file

@ -1,21 +1,24 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use GuzzleHttp\Client;
use App\Jobs\SyndicateBookmarkToTwitter;
use App\Models\Bookmark;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use App\Jobs\SyndicateBookmarkToTwitter;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class SyndicateBookmarkToTwitterJobTest extends TestCase
{
use DatabaseTransactions;
public function test_the_job()
/** @test */
public function weSendBookmarksToTwitter(): void
{
$json = json_encode([
'url' => 'https://twitter.com/123'

View file

@ -2,20 +2,21 @@
namespace Tests\Unit\Jobs;
use Tests\TestCase;
use App\Jobs\SyndicateNoteToTwitter;
use App\Models\Note;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;
use App\Jobs\SyndicateNoteToTwitter;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class SyndicateNoteToTwitterJobTest extends TestCase
{
use DatabaseTransactions;
public function test_the_job()
/** @test */
public function weSyndicateNotesToTwitter(): void
{
$json = json_encode([
'url' => 'https://twitter.com/i/web/status/123'