61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?hh // strict
|
|
|
|
namespace Tests\Services;
|
|
|
|
use App\Services\TenantResolver;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Slim\Psr7\Factory\ServerRequestFactory;
|
|
|
|
class TenantResolverTest extends TestCase
|
|
{
|
|
private TenantResolver $tenantResolver;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->tenantResolver = new TenantResolver();
|
|
}
|
|
|
|
public function testResolveTenantFromSubdomain(): void
|
|
{
|
|
$requestFactory = new ServerRequestFactory();
|
|
$request = $requestFactory->createServerRequest('GET', 'https://abc.merchantsofhope.org');
|
|
|
|
$tenant = $this->tenantResolver->resolveTenant($request);
|
|
|
|
$this->assertNotNull($tenant);
|
|
$this->assertEquals('abc', $tenant->getSubdomain());
|
|
$this->assertEquals('Abc Tenant', $tenant->getName());
|
|
}
|
|
|
|
public function testResolveTenantFromPath(): void
|
|
{
|
|
$requestFactory = new ServerRequestFactory();
|
|
$request = $requestFactory->createServerRequest('GET', 'https://merchantsofhope.org/xyz');
|
|
|
|
$tenant = $this->tenantResolver->resolveTenant($request);
|
|
|
|
$this->assertNotNull($tenant);
|
|
$this->assertEquals('xyz', $tenant->getSubdomain());
|
|
$this->assertEquals('Xyz Tenant', $tenant->getName());
|
|
}
|
|
|
|
public function testResolveTenantWithNoTenant(): void
|
|
{
|
|
$requestFactory = new ServerRequestFactory();
|
|
$request = $requestFactory->createServerRequest('GET', 'https://merchantsofhope.org');
|
|
|
|
$tenant = $this->tenantResolver->resolveTenant($request);
|
|
|
|
$this->assertNull($tenant);
|
|
}
|
|
|
|
public function testResolveTenantFromInvalidSubdomain(): void
|
|
{
|
|
$requestFactory = new ServerRequestFactory();
|
|
$request = $requestFactory->createServerRequest('GET', 'https://merchantsofhope.org');
|
|
|
|
$tenant = $this->tenantResolver->resolveTenant($request);
|
|
|
|
$this->assertNull($tenant);
|
|
}
|
|
} |