Skip to content

Commit

Permalink
test(testing): run flarum/testing package tests (#3844)
Browse files Browse the repository at this point in the history
* chore(testing): run flarum/testing packages tests back again

These tests were not run on each framework build, I enabled them again.
Two of the tests were failing so I disabled them for now, it is more
important to have some tests running than none at all.

* chore(testing): remove flarum/testing dedicated workflow

It is useless now that the tests are run in the framework repo.
Also this workflow was not working anymore.

---------

Co-authored-by: Sami Mazouz <[email protected]>
  • Loading branch information
n-peugnet and SychO9 authored Nov 29, 2024
1 parent 7f001df commit 08b3614
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
with:
enable_backend_testing: true
backend_directory: .
monorepo_tests: "framework/core extensions/akismet extensions/approval extensions/flags extensions/likes extensions/mentions extensions/nicknames extensions/statistics extensions/sticky extensions/subscriptions extensions/suspend extensions/tags extensions/messages"
monorepo_tests: "framework/core extensions/akismet extensions/approval extensions/flags extensions/likes extensions/mentions extensions/nicknames extensions/statistics extensions/sticky extensions/subscriptions extensions/suspend extensions/tags extensions/messages php-packages/testing/tests"
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@
"phpunit/phpunit": "^11.0",
"phpstan/phpstan": "^1.10.0",
"larastan/larastan": "2.9.12",
"symfony/var-dumper": "^7.0"
"symfony/var-dumper": "^7.0",
"flarum/testing-tests": "*@dev"
},
"config": {
"sort-packages": true
Expand Down Expand Up @@ -217,5 +218,11 @@
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
}
},
"repositories": [
{
"type": "path",
"url": "php-packages/testing/tests"
}
]
}
83 changes: 0 additions & 83 deletions php-packages/testing/.github/workflows/test.yml

This file was deleted.

13 changes: 10 additions & 3 deletions php-packages/testing/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"phpunit/phpunit": "^11.0"
},
"require-dev": {
"flarum/core": "*@dev"
"flarum/core": "*@dev",
"flarum/testing-tests": "*@dev"
},
"autoload": {
"psr-4": {
Expand All @@ -30,10 +31,16 @@
"dev-main": "2.x-dev"
}
},
"repositories": [{
"repositories": [
{
"type": "path",
"url": "../../*/*"
}],
},
{
"type": "path",
"url": "tests"
}
],
"minimum-stability": "dev",
"prefer-stable": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Flarum\Database\Migrator;
use Flarum\Extension\Extension;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Config;
use Flarum\Foundation\MaintenanceMode;
use Flarum\Foundation\Paths;
use Flarum\Settings\SettingsRepositoryInterface;
Expand Down Expand Up @@ -99,9 +100,13 @@ protected function setEnabledExtensions(array $enabledExtensions): void
*/
protected function getAssetsFilesystem(): Cloud
{
/** @var Config $config */
$config = $this->container->make(Config::class);
$adapter = new LocalFilesystemAdapter($this->paths->public.'/assets');

return new FilesystemAdapter(new \League\Flysystem\Filesystem($adapter), $adapter);
return new FilesystemAdapter(new \League\Flysystem\Filesystem($adapter), $adapter, [
'url' => $config->url().'/assets',
]);
}

protected function includeCurrentExtension(Collection $extensions, $package, string $packagePath): Collection
Expand Down
3 changes: 2 additions & 1 deletion php-packages/testing/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor/*
vendor/*
tests/.*.cache
13 changes: 12 additions & 1 deletion php-packages/testing/tests/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Minimal extension to test the flarum/testing package",
"type": "flarum-extension",
"require": {
"flarum/core": "^0.1.0@dev"
"flarum/core": "^2.0@dev"
},
"require-dev": {
"flarum/testing": "*@dev"
Expand All @@ -13,6 +13,17 @@
"Flarum\\Testing\\Tests\\": "tests/"
}
},
"extra": {
"flarum-extension": {
"title": "Testing",
"category": "feature",
"icon": {
"name": "fas fa-vial",
"backgroundColor": "#ABDC88",
"color": "#3F8A32"
}
}
},
"scripts": {
"test": [
"@test:unit",
Expand Down
1 change: 0 additions & 1 deletion php-packages/testing/tests/tests/.phpunit.result.cache

This file was deleted.

63 changes: 20 additions & 43 deletions php-packages/testing/tests/tests/integration/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
namespace Flarum\Testing\Tests\integration;

use Flarum\Extend;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Config;
use Flarum\Settings\DefaultSettingsRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
use Illuminate\Database\Schema\Builder;
use PHPUnit\Framework\Attributes\Test;

class TestCaseTest extends TestCase
{
/**
* @test
*/
#[Test]
public function admin_user_created_as_part_of_default_state()
{
$this->app();
Expand All @@ -34,9 +35,7 @@ public function admin_user_created_as_part_of_default_state()
$this->assertTrue($user->isAdmin());
}

/**
* @test
*/
#[Test]
public function can_add_settings_via_method()
{
$this->setting('hello', 'world');
Expand All @@ -48,20 +47,17 @@ public function can_add_settings_via_method()
$this->assertEquals('something_other_than_username', $settings->get('display_name_driver'));
}

/**
* @test
*/
#[Test]
public function settings_cleaned_up_from_previous_method()
{
$settings = $this->app()->getContainer()->make(SettingsRepositoryInterface::class);
$defaults = $this->app()->getContainer()->make(DefaultSettingsRepository::class);

$this->assertEquals(null, $settings->get('hello'));
$this->assertEquals(null, $settings->get('display_name_driver'));
$this->assertEquals($defaults->get('display_name_driver'), $settings->get('display_name_driver'));
}

/**
* @test
*/
#[Test]
public function can_add_config_via_method()
{
$this->config('hello', 'world');
Expand All @@ -75,9 +71,7 @@ public function can_add_config_via_method()
$this->assertEquals('value', $config['level1']['level2']);
}

/**
* @test
*/
#[Test]
public function config_cleaned_up_from_previous_method()
{
$config = $this->app()->getContainer()->make(Config::class);
Expand All @@ -87,9 +81,7 @@ public function config_cleaned_up_from_previous_method()
$this->assertFalse(isset($config['level1']['level2']));
}

/**
* @test
*/
#[Test]
public function current_extension_not_applied_by_default()
{
$response = $this->send(
Expand All @@ -99,9 +91,7 @@ public function current_extension_not_applied_by_default()
$this->assertStringNotContainsString('notARealSetting', $response->getBody()->getContents());
}

/**
* @test
*/
#[Test]
public function current_extension_applied_if_specified()
{
$this->extension('flarum-testing-tests');
Expand All @@ -113,9 +103,7 @@ public function current_extension_applied_if_specified()
$this->assertStringContainsString('notARealSetting', $response->getBody()->getContents());
}

/**
* @test
*/
#[Test]
public function current_extension_migrations_applied_if_specified()
{
$this->extension('flarum-testing-tests');
Expand All @@ -124,9 +112,7 @@ public function current_extension_migrations_applied_if_specified()
$this->assertTrue($tableExists);
}

/**
* @test
*/
#[Test]
public function current_extension_considered_enabled_after_boot()
{
$this->extension('flarum-testing-tests');
Expand All @@ -135,9 +121,7 @@ public function current_extension_considered_enabled_after_boot()
$this->assertTrue($enabled);
}

/**
* @test
*/
#[Test]
public function can_apply_extenders()
{
$this->extend(
Expand All @@ -151,9 +135,7 @@ public function can_apply_extenders()
$this->assertStringContainsString('notARealSetting', $response->getBody()->getContents());
}

/**
* @test
*/
#[Test]
public function can_apply_route_extenders()
{
$this->extend(
Expand All @@ -167,9 +149,7 @@ public function can_apply_route_extenders()
$this->assertEquals(200, $response->getStatusCode());
}

/**
* @test
*/
#[Test]
public function routes_added_by_current_extension_not_accessible_by_default()
{
$response = $this->send(
Expand All @@ -179,9 +159,7 @@ public function routes_added_by_current_extension_not_accessible_by_default()
$this->assertEquals(404, $response->getStatusCode());
}

/**
* @test
*/
#[Test]
public function routes_added_by_current_extension_accessible()
{
$this->extension('flarum-testing-tests');
Expand All @@ -193,14 +171,13 @@ public function routes_added_by_current_extension_accessible()
$this->assertEquals(200, $response->getStatusCode());
}

/**
* @test
*/
#[Test]
public function extension_url_correct()
{
$this->extension('flarum-testing-tests');
$expected = $this->app()->getContainer()->make('filesystem')->disk('flarum-assets')->url('/flarum-testing-tests/');
// We need to test this since we override it.
/** @var ExtensionManager $extensions */
$extensions = $this->app()->getContainer()->make('flarum.extensions');
$currExtension = $extensions->getExtension('flarum-testing-tests');
$baseAssetsUrl = $extensions->getAsset($currExtension, '');
Expand Down
2 changes: 1 addition & 1 deletion php-packages/testing/tests/tests/integration/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
* LICENSE file that was distributed with this source code.
*/

$setup = require __DIR__.'/../../../../php-packages/testing/bootstrap/monorepo.php';
$setup = require __DIR__.'/../../../bootstrap/monorepo.php';

$setup->run();
2 changes: 1 addition & 1 deletion php-packages/testing/tests/tests/phpunit.integration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
colors="true"
processIsolation="true"
stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
bootstrap="../../bootstrap/monorepo.php"
>
<source>
<include>
Expand Down
2 changes: 1 addition & 1 deletion php-packages/testing/tests/tests/phpunit.unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="../../../php-packages/testing/bootstrap/monorepo.php"
bootstrap="../../bootstrap/monorepo.php"
>
<source>
<include>
Expand Down

0 comments on commit 08b3614

Please sign in to comment.