Skip to content

Commit

Permalink
[2.x] New version
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter committed Mar 7, 2024
2 parents ae4bc8f + 39e417a commit c9eca42
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 48 deletions.
10 changes: 6 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
Expand All @@ -18,4 +15,9 @@
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="APP_DEBUG" value="true"/>
</php>
<source>
<include>
<directory>src/</directory>
</include>
</source>
</phpunit>
18 changes: 9 additions & 9 deletions src/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public function away(string $replace, string $url, bool $blank = true): static
{
$this->links[] = (object) [
'replace' => trim($replace, '{}'),
'url' => $url,
'blank' => $blank,
'url' => $url,
'blank' => $blank,
];

usort($this->links, static function (object $first, object $second): int {
Expand Down Expand Up @@ -315,8 +315,8 @@ public function tag(string ...$tags): static
public function toArray(): array
{
return [
'message' => $this->message,
'types' => $this->types,
'message' => $this->message,
'types' => $this->types,
'dismissible' => $this->dismissible,
];
}
Expand Down Expand Up @@ -359,12 +359,12 @@ public function __toString(): string
public function __serialize(): array
{
return [
'persist_key' => $this->persistKey,
'message' => $this->message,
'types' => $this->types,
'links' => $this->links,
'persist_key' => $this->persistKey,
'message' => $this->message,
'types' => $this->types,
'links' => $this->links,
'dismissible' => $this->dismissible,
'tags' => $this->tags,
'tags' => $this->tags,
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/Bag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Bag
* Create a new Bag instance.
*
* @param string[] $tags
* @param string[] $persisted
* @param array<string, int> $persisted
*/
public function __construct(protected array $tags, protected array $persisted = [])
{
Expand All @@ -40,7 +40,7 @@ public function __construct(protected array $tags, protected array $persisted =
/**
* Returns all a key-index map of all persisted alerts.
*
* @return string[]
* @return array<string, int>
*/
public function getPersisted(): array
{
Expand Down Expand Up @@ -149,7 +149,7 @@ public function hasPersistent(string $key): bool
/**
* Locates the key of a persistent alert.
*/
protected function whichPersistent(string $key): ?string
protected function whichPersistent(string $key): ?int
{
return $this->persisted[$key] ?? null;
}
Expand Down
1 change: 1 addition & 0 deletions src/BogusAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @internal This is only a bogus alert that does nothing, and it's not added to the Alert bag.
*
* @codeCoverageIgnore
*/
class BogusAlert extends Alert
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Middleware/AddAlertsToJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Laragear\Alerts\Http\Middleware;

use Closure;
use function config;
use function data_set;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Laragear\Alerts\Bag;

use function config;
use function data_set;

class AddAlertsToJson
{
/**
Expand Down
1 change: 1 addition & 0 deletions src/Http/Middleware/StoreAlertsInSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Http\Request;
use Laragear\Alerts\Alert;
use Laragear\Alerts\Bag;

use function array_merge;
use function in_array;

Expand Down
1 change: 1 addition & 0 deletions src/RendererManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @method \Laragear\Alerts\Contracts\Renderer driver($driver = null)
*
* @codeCoverageIgnore
*/
class RendererManager extends Manager
Expand Down
14 changes: 7 additions & 7 deletions src/Renderers/BootstrapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class BootstrapRenderer implements Renderer
* @var array<string, string|string[]>
*/
protected const TYPE_CLASSES = [
'primary' => 'alert-primary',
'primary' => 'alert-primary',
'secondary' => 'alert-secondary',
'success' => 'alert-success',
'danger' => 'alert-danger',
'warning' => 'alert-warning',
'info' => 'alert-info',
'light' => 'alert-light',
'dark' => 'alert-dark',
'success' => 'alert-success',
'danger' => 'alert-danger',
'warning' => 'alert-warning',
'info' => 'alert-info',
'light' => 'alert-light',
'dark' => 'alert-dark',
];

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Renderers/CompilesAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Arr;
use Laragear\Alerts\Alert;

use function array_column;
use function array_map;
use function array_merge;
Expand All @@ -20,8 +21,8 @@ trait CompilesAlert
public function compileAlert(Alert $alert): object
{
return (object) [
'message' => static::compileMessage($alert),
'classes' => static::compileClasses($alert),
'message' => static::compileMessage($alert),
'classes' => static::compileClasses($alert),
'dismissible' => $alert->isDismissible(),
];
}
Expand Down
12 changes: 6 additions & 6 deletions src/Renderers/TailwindRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class TailwindRenderer implements Renderer
* @var array<string, string|string[]>
*/
protected const TYPE_CLASSES = [
'success' => ['bg-green-100', 'ring-green-500/20', 'text-green-900'],
'failure' => ['bg-red-100', 'ring-red-500/20', 'text-red-900'],
'warning' => ['bg-yellow-100', 'ring-yellow-500/20', 'text-yellow-900'],
'info' => ['bg-blue-100', 'ring-blue-500/20', 'text-blue-900'],
'light' => ['bg-white', 'ring-gray-900/5', 'text-gray-900'],
'dark' => ['bg-gray-800', 'ring-white/10', 'text-gray-300'],
'success' => ['bg-green-100', 'ring-green-500/20', 'text-green-900'],
'failure' => ['bg-red-100', 'ring-red-500/20', 'text-red-900'],
'warning' => ['bg-yellow-100', 'ring-yellow-500/20', 'text-yellow-900'],
'info' => ['bg-blue-100', 'ring-blue-500/20', 'text-blue-900'],
'light' => ['bg-white', 'ring-gray-900/5', 'text-gray-900'],
'dark' => ['bg-gray-800', 'ring-white/10', 'text-gray-300'],
];

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Testing/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Testing\Assert as PHPUnit;
use Laragear\Alerts\Alert;
use Laragear\Alerts\Testing\Fakes\BagFake;

use function in_array;
use function is_array;
use function is_string;
Expand Down Expand Up @@ -95,8 +96,8 @@ public function withAway(string $replace, string $url, bool $blank = true): stat
{
$this->links[] = (object) [
'replace' => $replace,
'url' => $url,
'blank' => $blank,
'url' => $url,
'blank' => $blank,
];

usort($this->links, static function (object $first, object $second): int {
Expand Down
13 changes: 7 additions & 6 deletions tests/AlertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Tests;

use function alert;
use function app;
use BadMethodCallException;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\URL;
use Laragear\Alerts\Alert;
use Laragear\Alerts\Bag;

use function alert;
use function app;

class AlertTest extends TestCase
{
public function test_creates_default_instance(): void
Expand Down Expand Up @@ -159,8 +160,8 @@ public function test_alert_to_array(): void

static::assertEquals(
[
'message' => 'foo',
'types' => ['bar', 'foo'],
'message' => 'foo',
'types' => ['bar', 'foo'],
'dismissible' => true,
],
$alert->toArray()
Expand All @@ -187,8 +188,8 @@ public function test_alert_from_json(): void
{
$alert = Alert::fromArray(
[
'message' => 'foo',
'types' => ['foo', 'bar'],
'message' => 'foo',
'types' => ['foo', 'bar'],
'dismissible' => true,
'persist_key' => 'baz',
]
Expand Down
5 changes: 3 additions & 2 deletions tests/Blade/Components/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Tests\Blade\Components;

use function alert;
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Illuminate\Support\Collection;
use Laragear\Alerts\Alert;
use Laragear\Alerts\Bag;
use Laragear\Alerts\Contracts\Renderer;
use Tests\TestCase;

use function alert;

class ContainerTest extends TestCase
{
use InteractsWithViews;
Expand All @@ -30,7 +31,7 @@ public function test_doesnt_renders_without_alerts(): void
static::assertEquals(<<<'EOT'
<div class="container"></div>
EOT
, (string) $this->blade('<div class="container"><x-alerts-container /></div>')
, (string) $this->blade('<div class="container"><x-alerts-container /></div>')
);
}

Expand Down
5 changes: 3 additions & 2 deletions tests/Http/Middleware/StoreAlertsInSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Tests\Http\Middleware;

use function alert;
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Illuminate\Support\Facades\Route;
use Laragear\Alerts\Http\Middleware\StoreAlertsInSession;
use function redirect;
use Tests\TestCase;

use function alert;
use function redirect;

class StoreAlertsInSessionTest extends TestCase
{
use InteractsWithViews;
Expand Down
3 changes: 2 additions & 1 deletion tests/Renderers/BootstrapRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Tests\Renderers;

use function alert;
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Laragear\Alerts\Bag;
use Tests\TestCase;

use function alert;

class BootstrapRendererTest extends TestCase
{
use InteractsWithViews;
Expand Down
3 changes: 2 additions & 1 deletion tests/Renderers/TailwindRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Tests\Renderers;

use function alert;
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Laragear\Alerts\Bag;
use Tests\TestCase;

use function alert;

class TailwindRendererTest extends TestCase
{
use InteractsWithViews;
Expand Down
3 changes: 2 additions & 1 deletion tests/Testing/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Tests\Testing;

use function e;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\URL;
use Laragear\Alerts\Facades\Alert;
use Laragear\Alerts\Testing\Fakes\BagFake;
use PHPUnit\Framework\AssertionFailedError;
use Tests\TestCase;

use function e;

class BuilderTest extends TestCase
{
protected BagFake $bag;
Expand Down

0 comments on commit c9eca42

Please sign in to comment.