-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Fangx's Packages | ||
* | ||
* @link https://nfangxu.com | ||
* @document https://pkg.nfangxu.com | ||
* @contact [email protected] | ||
* @author nfangxu | ||
* @license https://pkg.nfangxu.com/license | ||
*/ | ||
|
||
namespace Fangx\Tests; | ||
|
||
use Fangx\Tests\Stub\Alert; | ||
use Fangx\Tests\Stub\AlertSlot; | ||
use Fangx\View\Contract\FactoryInterface; | ||
use Fangx\View\HyperfViewEngine; | ||
use Hyperf\Config\Config; | ||
use Hyperf\Contract\ConfigInterface; | ||
use Hyperf\Di\Container; | ||
use Hyperf\Utils\ApplicationContext; | ||
use Hyperf\View\Mode; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ConfigRegisterTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
/** @var Container $container */ | ||
$container = ApplicationContext::getContainer(); | ||
|
||
$container->set(ConfigInterface::class, new Config([ | ||
'view' => [ | ||
'engine' => HyperfViewEngine::class, | ||
'mode' => Mode::SYNC, | ||
'config' => [ | ||
'view_path' => __DIR__ . '/storage/view/', | ||
'cache_path' => __DIR__ . '/storage/cache/', | ||
], | ||
'components' => [ | ||
'alert' => Alert::class, | ||
'alert-slot' => AlertSlot::class, | ||
], | ||
'namespaces' => [ | ||
'admin' => __DIR__ . '/admin' | ||
], | ||
], | ||
])); | ||
} | ||
|
||
public function testRegisterComponents() | ||
{ | ||
$this->assertSame('success', $this->view('simple_8', ['message' => 'success'])); | ||
$this->assertSame('success', $this->view('simple_9', ['message' => 'success'])); | ||
} | ||
|
||
public function testRegisterNamespace() | ||
{ | ||
$this->assertSame('from_admin', $this->view('admin::simple_3')); | ||
$this->assertSame('from_vendor', $this->view('admin::simple_4')); | ||
} | ||
|
||
protected function view(string $view, $data = [], array $mergeData = []): string | ||
{ | ||
$container = ApplicationContext::getContainer(); | ||
|
||
/** @var FactoryInterface $factory */ | ||
$factory = $container->get(FactoryInterface::class); | ||
|
||
$content = $factory->make($view, $data, $mergeData)->render(); | ||
|
||
return trim($content); | ||
} | ||
} |