Skip to content
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
23 changes: 17 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:

# Unit tests back (phpunit)
Expand All @@ -11,14 +14,10 @@ jobs:
strategy:
matrix:
include:
- php: 8.4
env:
LARAVEL: 10.*
TESTBENCH: 8.*
- php: 8.3
env:
LARAVEL: 10.*
TESTBENCH: 8.*
LARAVEL: 11.*
TESTBENCH: 9.*
- php: 8.4
env:
LARAVEL: 11.*
Expand All @@ -27,26 +26,38 @@ jobs:
env:
LARAVEL: 12.*
TESTBENCH: 10.*
- php: 8.5
env:
LARAVEL: 12.*
TESTBENCH: 10.*
env: ${{ matrix.env }}
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, dom, fileinfo, mysql

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: |
composer require "laravel/framework:${LARAVEL}" "orchestra/testbench:${TESTBENCH}" --no-interaction --no-update --prefer-dist
composer update --prefer-stable --prefer-dist --no-interaction

- name: Run Security Audit
run: composer audit

- name: Execute tests (Unit and Feature tests) via PHPUnit
run: ./vendor/bin/phpunit
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"author": "Code 16",
"require": {
"php": "^8.0",
"illuminate/contracts": "^10.0|^11.0|^12.0",
"illuminate/support": "^10.0|^11.0|^12.0"
"illuminate/contracts": "^11.0|^12.0",
"illuminate/support": "^11.0|^12.0"
},
"require-dev": {
"code16/pint-config": "^1.2",
"laravel/framework": "^10.0|^11.0|^12.0",
"laravel/framework": "^11.0|^12.0",
"laravel/pint": "^1.21",
"orchestra/testbench": "^8.0|^9.0|^10.0",
"phpunit/phpunit": "^10.0|^11.0"
"phpunit/phpunit": "^10.0|^11.0|^12.0"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 9 additions & 8 deletions tests/Unit/Rules/EmbeddableUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use Code16\Embed\Services\YouTube;
use Code16\Embed\Tests\EmbedTestCase;
use Illuminate\Support\Facades\Validator;
use PHPUnit\Framework\Attributes\Test;

class EmbeddableUrlTest extends EmbedTestCase
{
/** @test */
#[Test]
public function it_passes_a_validUrl_for_any_service()
{
$validUrls = [
Expand All @@ -33,7 +34,7 @@ public function it_passes_a_validUrl_for_any_service()
$this->assertTrue(true);
}

/** @test */
#[Test]
public function it_passes_for_an_allowed_service()
{
$url = 'https://www.youtube.com/embed/dQw4w9WgXcQ';
Expand All @@ -52,7 +53,7 @@ public function it_passes_for_an_allowed_service()
$this->assertTrue(true);
}

/** @test */
#[Test]
public function it_passes_for_multiple_allowed_services()
{
$validUrls = [
Expand All @@ -77,7 +78,7 @@ public function it_passes_for_multiple_allowed_services()
$this->assertTrue(true);
}

/** @test */
#[Test]
public function it_fails_for_an_invalid_url()
{
$exception = null;
Expand All @@ -94,7 +95,7 @@ function ($message) use (&$exception) {
$this->assertNotNull($exception);
}

/** @test */
#[Test]
public function it_fails_for_an_unsupported_service()
{
$exception = null;
Expand All @@ -112,7 +113,7 @@ function ($message) use (&$exception) {
$this->assertNotNull($exception);
}

/** @test */
#[Test]
public function it_replaces_supported_services_in_message_with_no_services_specified()
{
$url = 'https://www.real.com/video/xg4y8d';
Expand All @@ -133,7 +134,7 @@ protected function assertValidationMessage($url, $rule, $expectedMessage)
$this->assertEquals($expectedMessage, $validator->messages()->get($attributeKey)[0]);
}

/** @test */
#[Test]
public function it_replaces_supported_service_in_message()
{
$url = 'https://www.real.com/video/xg4y8d';
Expand All @@ -143,7 +144,7 @@ public function it_replaces_supported_service_in_message()
$this->assertValidationMessage($url, $rule, $expectedMessage);
}

/** @test */
#[Test]
public function it_replaces_supported_services_list_in_message()
{
$url = 'https://www.real.com/video/xg4y8d';
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/ServiceBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Code16\Embed\Tests\Fakes\Services\FakeServiceOne;
use Code16\Embed\Tests\Fakes\Services\FakeServiceTwo;
use Code16\Embed\ValueObjects\Url;
use PHPUnit\Framework\Attributes\Test;

class ServiceBaseTest extends EmbedTestCase
{
/** @test */
#[Test]
public function it_can_guess_view_name()
{
$this->assertEquals(
Expand All @@ -23,7 +24,7 @@ public function it_can_guess_view_name()
);
}

/** @test */
#[Test]
public function it_can_pass_view_data()
{
$this->assertEquals(
Expand Down
7 changes: 4 additions & 3 deletions tests/Unit/ServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use Code16\Embed\Tests\Fakes\Services\FakeServiceOne;
use Code16\Embed\Tests\Fakes\Services\FakeServiceTwo;
use Code16\Embed\ValueObjects\Url;
use PHPUnit\Framework\Attributes\Test;

class ServiceFactoryTest extends EmbedTestCase
{
/** @test */
#[Test]
public function it_can_get_a_service_by_url()
{
ServiceFactory::fake();
Expand All @@ -20,15 +21,15 @@ public function it_can_get_a_service_by_url()
$this->assertInstanceOf(FakeServiceTwo::class, ServiceFactory::getByUrl(new Url('https://two.com')));
}

/** @test */
#[Test]
public function it_throws_an_exception_if_no_service_exists_to_handle_the_url()
{
ServiceFactory::fake();

$this->assertNull(ServiceFactory::getByUrl(new Url('https://non-existing-service.com')));
}

/** @test */
#[Test]
public function it_can_get_a_fallback_service()
{
$this->assertInstanceOf(Fallback::class,
Expand Down
7 changes: 4 additions & 3 deletions tests/Unit/Services/ServiceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use Code16\Embed\ServiceContract;
use Code16\Embed\Tests\EmbedTestCase;
use Code16\Embed\ValueObjects\Url;
use PHPUnit\Framework\Attributes\Test;

abstract class ServiceTestCase extends EmbedTestCase
{
/** @test */
#[Test]
public function it_renders_the_correct_view()
{
$this->assertEquals('embed::services.'.$this->expectedViewName(), $this->service()->fullViewName());
Expand All @@ -28,7 +29,7 @@ abstract protected function serviceClass(): string;

abstract protected function validUrls(): array;

/** @test */
#[Test]
public function it_detects_appropriate_urls()
{
foreach ($this->validUrls() as $url) {
Expand All @@ -39,7 +40,7 @@ public function it_detects_appropriate_urls()
}
}

/** @test */
#[Test]
public function it_has_expected_view_data()
{
foreach ($this->expectedViewData() as $key => $value) {
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/ValueObjects/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
use Code16\Embed\Tests\EmbedTestCase;
use Code16\Embed\ValueObjects\Url;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\Test;

class UrlTest extends EmbedTestCase
{
/** @test */
#[Test]
public function it_accepts_a_valid_url()
{
$this->assertInstanceOf(Url::class, new Url('https://example.org'));
$this->assertInstanceOf(Url::class, new Url('http://example.org'));
}

/** @test */
#[Test]
public function it_throws_an_exception_for_an_invalid_url()
{
$this->expectException(InvalidArgumentException::class);
new Url('not-a-val..id-url');
}

/** @test */
#[Test]
public function it_can_be_cast_to_a_string()
{
$url = new Url('https://example.org');
$this->assertEquals('https://example.org', (string) $url);
}

/** @test */
#[Test]
public function it_attempts_to_prepend_https_if_missing()
{
$url = new Url('example.org');
Expand Down
Loading