Skip to content

Commit

Permalink
Merge pull request #44 from drewroberts/kyle-fix-failing-nova-tests
Browse files Browse the repository at this point in the history
Fix Nova and model tests
  • Loading branch information
drewroberts authored Mar 12, 2021
2 parents 0186f5b + e83a42e commit fdb7b09
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
],
"require": {
"php": "^7.4|^8.0",
"silvanite/nova-field-cloudinary": "^1.3",
"cloudinary/cloudinary_php": "^1.20.0",
"silvanite/nova-field-cloudinary": "^1.3.2",
"spatie/eloquent-sortable": "^3.11.0",
"tipoff/authorization": "^2.5.1",
"tipoff/laravel-google-api": "^1.3.1",
"tipoff/support": "^1.6.0"
},
"require-dev": {
"php-mock/php-mock-phpunit": "^2.6",
"php-mock/php-mock-mockery": "^1.3",
"tipoff/test-support": "^1.2.0"
},
"autoload": {
Expand Down
10 changes: 10 additions & 0 deletions tests/Feature/Nova/ImageResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DrewRoberts\Media\Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;

class ImageResourceTest extends TestCase
{
Expand All @@ -17,6 +18,15 @@ class ImageResourceTest extends TestCase
/** @test */
public function index()
{
Config::set('app.key', 'base64:CA0WFs+ECA4gq/G95GpRwEaYsoNdUF0cAziYkc83ISE=');

Config::set('filesystems.disks.cloudinary', [
'driver' => 'cloudinary',
'api_key' => env('CLOUDINARY_API_KEY', 'nonsense'),
'api_secret' => env('CLOUDINARY_API_SECRET', 'nonsense'),
'cloud_name' => env('CLOUDINARY_CLOUD_NAME', 'nonsense'),
]);

Image::factory()->count(1)->create();

$this->actingAs(self::createPermissionedUser('view images', true));
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/Nova/TagResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DrewRoberts\Media\Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;

class TagResourceTest extends TestCase
{
Expand All @@ -17,6 +18,8 @@ class TagResourceTest extends TestCase
/** @test */
public function index()
{
Config::set('app.key', 'base64:CA0WFs+ECA4gq/G95GpRwEaYsoNdUF0cAziYkc83ISE=');

Tag::factory()->count(1)->create();

$this->actingAs(self::createPermissionedUser('view tags', true));
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/Nova/VideoResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DrewRoberts\Media\Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;

class VideoResourceTest extends TestCase
{
Expand All @@ -17,6 +18,8 @@ class VideoResourceTest extends TestCase
/** @test */
public function index()
{
Config::set('app.key', 'base64:CA0WFs+ECA4gq/G95GpRwEaYsoNdUF0cAziYkc83ISE=');

Video::factory()->count(1)->create();

$this->actingAs(self::createPermissionedUser('view videos', true));
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DrewRoberts\Media\MediaServiceProvider;
use DrewRoberts\Media\Tests\Support\Providers\NovaPackageServiceProvider;
use Laravel\Nova\NovaCoreServiceProvider;
use Silvanite\NovaFieldCloudinary\Providers\PackageServiceProvider;
use Spatie\Permission\PermissionServiceProvider;
use Tipoff\Authorization\AuthorizationServiceProvider;
use Tipoff\Support\SupportServiceProvider;
Expand All @@ -23,6 +24,7 @@ protected function getPackageProviders($app)
MediaServiceProvider::class,
NovaCoreServiceProvider::class,
NovaPackageServiceProvider::class,
PackageServiceProvider::class,
];
}
}
15 changes: 7 additions & 8 deletions tests/Unit/Models/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

use DrewRoberts\Media\Models\Image;
use DrewRoberts\Media\Models\Video;
use DrewRoberts\Media\Tests\Support\Models\User;
use DrewRoberts\Media\Tests\TestCase;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use phpmock\phpunit\PHPMock;
use Mockery;
use phpmock\mockery\PHPMockery;
use Tipoff\Authorization\Models\User;

class ImageTest extends TestCase
{
use RefreshDatabase,
PHPMock,
WithFaker;

/** @test */
Expand Down Expand Up @@ -99,21 +99,20 @@ public function it_has_an_url()
/** @test */
public function it_determines_the_dimensions_if_empty()
{
PHPMockery::mock('DrewRoberts\Media\Models', 'getimagesize')->andReturn([24, 60]);

$image = Image::factory()->make([
'filename' => 'test.jpg',
'width' => null,
'height' => null,
]);

$this->getFunctionMock('DrewRoberts\Media\Models', 'getimagesize')
->expects($this->once())
->with($image->url)
->willReturn([24, 60]);

$image->save();

$this->assertEquals(24, $image->width);
$this->assertEquals(60, $image->height);

Mockery::close();
}

/** @test */
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace DrewRoberts\Media\Tests\Unit\Models;

use DrewRoberts\Media\Models\Tag;
use DrewRoberts\Media\Tests\Support\Models\User;
use DrewRoberts\Media\Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tipoff\Authorization\Models\User;

class TagTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/VideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use DrewRoberts\Media\Models\Image;
use DrewRoberts\Media\Models\Video;
use DrewRoberts\Media\Tests\Support\Models\User;
use DrewRoberts\Media\Tests\TestCase;
use Exception;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Carbon;
use Tipoff\Authorization\Models\User;

class VideoTest extends TestCase
{
Expand Down

0 comments on commit fdb7b09

Please sign in to comment.