Skip to content

Commit

Permalink
temp wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmichael123 committed Mar 18, 2021
1 parent 4f3c1e0 commit a451d4e
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ build
composer.lock
docs
vendor
coverage
coverage
.env
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":480:{a:2:{s:7:"defects";a:2:{s:63:"Meema\CloudFront\Tests\CloudFrontTest::it_can_bust_a_cache_item";i:2;s:79:"/Users/glenn/Documents/Projects/laravel-cloudfront/tests/CloudFrontTest.php::it";i:4;}s:5:"times";a:3:{s:63:"Meema\CloudFront\Tests\CloudFrontTest::it_can_bust_a_cache_item";d:0.11;s:81:"/Users/glenn/Documents/Projects/laravel-cloudfront/tests/ExampleTest.php::example";d:0.002;s:79:"/Users/glenn/Documents/Projects/laravel-cloudfront/tests/CloudFrontTest.php::it";d:1.278;}}}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
},
"require-dev": {
"orchestra/testbench": "^3.5.0|^3.6.0|^4.0|^5.0|^6.0",
"phpunit/phpunit": "^5.0|^6.0|^8.0|^9.3"
"pestphp/pest": "^1.0",
"phpunit/phpunit": "^5.0|^6.0|^8.0|^9.3",
"vlucas/phpdotenv": "^4.2|^5.3"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>
83 changes: 52 additions & 31 deletions tests/CloudFrontTest.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
<?php

namespace Meema\CloudFront\Tests;

use Aws\CloudFront\CloudFrontClient;

class CloudFrontTest extends CloudFrontTestCase
{
/**
* @var \Aws\CloudFront\CloudFrontClient
*/
protected $client;

/**
* Setup client and results.
*
* @return void
*/
public function setUp(): void
{
parent::setUp();

$this->client = $this->getMockBuilder(CloudFrontClient::class)
->disableOriginalConstructor()
->getMock();
}

/** @test */
public function it_can_bust_a_cache_item()
{
$this->markTestIncomplete();
}
}
// namespace Meema\CloudFront\Tests;

// use Aws\CloudFront\CloudFrontClient;

// class CloudFrontTest extends CloudFrontTestCase
// {
// /**
// * @var \Aws\CloudFront\CloudFrontClient
// */
// protected $client;

// /**
// * Setup client and results.
// *
// * @return void
// */
// public function setUp(): void
// {
// parent::setUp();

// $this->client = $this->getMockBuilder(CloudFrontClient::class)
// ->disableOriginalConstructor()
// ->getMock();
// }

// /** @test */
// public function it_can_bust_a_cache_item()
// {
// $this->markTestIncomplete();
// }
// }

use Meema\CloudFront\Facades\CloudFront;

uses(Meema\CloudFront\Tests\CloudFrontTestCase::class);

beforeEach(function () {
$this->initializeDotEnv();
$this->initializeSettings();
});

it('can fetch cloudfront client', function () {
$client = CloudFront::getClient();

$this->assertTrue(!is_null($client));
});

it('can invalidate image', function () {
$paths = '/glenn/1/2/butterfly.jpg';

CloudFront::invalidate($paths, config('cloudfront.distribution_ops_id'));
});
24 changes: 24 additions & 0 deletions tests/CloudFrontTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Meema\CloudFront\Tests;

use Dotenv\Dotenv;
use Illuminate\Support\Facades\Config;
use Meema\CloudFront\Providers\CloudFrontServiceProvider;
use Orchestra\Testbench\TestCase;

Expand All @@ -11,4 +13,26 @@ protected function getPackageProviders($app)
{
return [CloudFrontServiceProvider::class];
}
public function initializeDotEnv()
{
if (! file_exists(__DIR__.'/../.env')) {
return;
}

$dotenv = Dotenv::createImmutable(dirname(__DIR__));
$dotenv->load();
}

public function initializeSettings()
{
// let's make sure these config values are set
Config::set('cloudfront.credentials.key', env('AWS_ACCESS_KEY_ID'));
Config::set('cloudfront.credentials.secret', env('AWS_SECRET_ACCESS_KEY'));
Config::set('cloudfront.disk', env('REKOGNITION_DISK', 's3'));
Config::set('cloudfront.distribution_id', env('AWS_CLOUDFRONT_DISTRIBUTION_ID'));
Config::set('cloudfront.ops_distribution_id', env('AWS_CLOUDFRONT_OPS_DISTRIBUTION_ID'));
Config::set('cloudfront.distribution_url', env('AWS_CLOUDFRONT_URL'));
Config::set('cloudfront.ops_distribution_url', env('AWS_CLOUDFRONT_OPS_URL'));
Config::set('filesystems.disks.s3.bucket', env('AWS_S3_BUCKET'));
}
}
3 changes: 3 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

uses(Meema\CloudFront\Tests\CloudFrontTestCase::class);

0 comments on commit a451d4e

Please sign in to comment.