Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VojislavD committed Feb 8, 2024
1 parent 983abed commit 844eff2
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
.phpunit.result.cache
.phpunit.result.cache
.phpunit.cache
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ npm install && npm run build

Components will use `primary`, `primary-dark`, `secondary` and `secondary-dark` colors. You should configure these colors in your `tailwind.config.js` file.

If you want to change colors or customize anything else, you can publish all components with:
If you want to change colors or customize anything else, you can publish all components views with:

```bash
php artisan vendor:publish --tag="tall-components"
php artisan vendor:publish --tag="tall-components-views"
```

To change colors, just find `primary`, `primary-dark`, `secondary` or `secondary-dark` in the component and replace them with color you want to use.
Expand Down
27 changes: 7 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
Expand All @@ -31,4 +13,9 @@
<env name="DB_DATABASE" value=":memory:"/>
<env name="APP_KEY" value="base64:2fl+Ktvkfl+Fuz4Qp/A75G2RTiWVA/ZoKZvp6fiiM10="/>
</php>
</phpunit>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
62 changes: 62 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace TallComponents\Tests;

use Livewire\LivewireServiceProvider;
use TallComponents\TallComponentsServiceProvider;

class TestCase extends \Orchestra\Testbench\TestCase
{
/**
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->cleanState();
}

/**
* @return void
*/
public function tearDown(): void
{
$this->cleanState();
parent::tearDown();
}

/**
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
public function getEnvironmentSetUp($app)
{

}

/**
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
public function getPackageProviders($app)
{
return [
LivewireServiceProvider::class,
TallComponentsServiceProvider::class,
];
}

/**
* @return void
*/
private function cleanState()
{
if (file_exists(resource_path('/views/components/tc/modal.blade.php'))) {
unlink(resource_path('/views/components/tc/modal.blade.php'));
rmdir(resource_path('/views/components/tc'));
rmdir(resource_path('/views/components/'));
}
}
}
45 changes: 45 additions & 0 deletions tests/Unit/PublishViewsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace TallComponents\Tests\Unit;

use Illuminate\Support\Facades\File;
use TallComponents\Tests\TestCase;

class PublishViewsTest extends TestCase
{
/** @test */
public function test_publish_view_for_modal_when_not_exists()
{
mkdir(resource_path('views/components/tc'), 0777, true);

$this->assertFalse(file_exists(resource_path('views/components/tc/modal.blade.php')));

$this->artisan('vendor:publish --tag="tall-components-views"');

$this->assertTrue(file_exists(resource_path('views/components/tc/modal.blade.php')));

$this->assertEquals(
file_get_contents(__DIR__.'/../../resources/views/components/modal.blade.php'),
file_get_contents(resource_path('views/components/tc/modal.blade.php'))
);
}

/** @test */
public function test_publish_view_for_modal_when_already_exists()
{
mkdir(resource_path('views/components/tc'), 0777, true);

$this->assertFalse(file_exists(resource_path('views/components/tc/modal.blade.php')));

File::put(resource_path('views/components/tc/').'modal.blade.php', 'Views test');

$this->artisan('vendor:publish --tag="tall-components-views"');

$this->assertTrue(file_exists(resource_path('views/components/tc/modal.blade.php')));

$this->assertEquals(
'Views test',
file_get_contents(resource_path('views/components/tc/modal.blade.php'))
);
}
}

0 comments on commit 844eff2

Please sign in to comment.