-
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.
Merge pull request #2 from bpolaszek/ringcentral-support
Add RingCentral/PSR7 factory
- Loading branch information
Showing
6 changed files
with
93 additions
and
6 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
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,38 @@ | ||
<?php | ||
|
||
namespace BenTools\UriFactory\Adapter; | ||
|
||
use BenTools\UriFactory\UriFactoryInterface; | ||
use RingCentral\Psr7\Uri; | ||
use Psr\Http\Message\UriInterface; | ||
|
||
final class RingCentralAdapter implements AdapterInterface | ||
{ | ||
protected function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createUri(string $uri = ''): UriInterface | ||
{ | ||
return new Uri($uri); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function factory(): UriFactoryInterface | ||
{ | ||
return new self; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function isInstalled(): bool | ||
{ | ||
return class_exists('\RingCentral\Psr7\Uri'); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace BenTools\UriFactory\Tests\Adapter; | ||
|
||
use BenTools\UriFactory\Adapter\RingCentralAdapter; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\UriInterface; | ||
use function BenTools\UriFactory\Helper\current_location; | ||
|
||
class RingCentralAdapterTest extends TestCase | ||
{ | ||
|
||
public function testClassCheck() | ||
{ | ||
$this->assertEquals(class_exists('RingCentral\Psr7\Uri'), RingCentralAdapter::isInstalled()); | ||
} | ||
|
||
public function testFactory() | ||
{ | ||
$factory = RingCentralAdapter::factory(); | ||
$this->assertInstanceOf(RingCentralAdapter::class, $factory); | ||
} | ||
|
||
public function testUri() | ||
{ | ||
$factory = RingCentralAdapter::factory(); | ||
$uri = $factory->createUri('http://www.example.net'); | ||
$this->assertInstanceOf(UriInterface::class, $uri); | ||
} | ||
|
||
public function testInFactory() | ||
{ | ||
$_SERVER['HTTP_HOST'] = 'localhost'; | ||
$_SERVER['REQUEST_URI'] = '/foo/bar?foo=bar&baz=bat'; | ||
$uri = current_location(RingCentralAdapter::factory()); | ||
$this->assertInstanceOf('RingCentral\Psr7\Uri', $uri); | ||
unset($_SERVER['REQUEST_URI'], $_SERVER['HTTP_HOST']); | ||
} | ||
} |