Commit d321c14d authored by Emiliano Balbuena's avatar Emiliano Balbuena

(test): Spec tests

1 merge request!308WIP: (feat): Minds Pro
Pipeline #82841696 failed with stages
in 4 minutes and 11 seconds
......@@ -24,16 +24,20 @@ class TraefikDynamoDb implements EdgeRouterInterface
/**
* TraefikDynamoDb constructor.
* @param Config $config
* @param DynamoDbClient $dynamoDb
*/
public function __construct(
$config = null
$config = null,
$dynamoDb = null
) {
$this->config = $config ?: Di::_()->get('Config');
$this->dynamoDb = $dynamoDb;
}
public function initialize(): EdgeRouterInterface
{
$awsConfig = $this->config->get('aws');
$opts = [
'region' => $awsConfig['region']
];
......@@ -64,7 +68,7 @@ class TraefikDynamoDb implements EdgeRouterInterface
return false;
}
$userGuid = $settings->getUserGuid();
$userGuid = (string) $settings->getUserGuid();
$marshaler = new Marshaler();
$entry = $marshaler->marshalJson(json_encode([
......
<?php
namespace Spec\Minds\Core\Pro\Domain\EdgeRouters;
use Aws\DynamoDb\DynamoDbClient;
use Minds\Core\Config;
use Minds\Core\Pro\Domain\EdgeRouters\TraefikDynamoDb;
use Minds\Core\Pro\Settings;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class TraefikDynamoDbSpec extends ObjectBehavior
{
/** @var Config */
protected $config;
/** @var DynamoDbClient */
protected $dynamoDb;
public function let(
Config $config,
DynamoDbClient $dynamoDbClient
) {
$this->config = $config;
$this->dynamoDb = $dynamoDbClient;
$this->beConstructedWith($config, $dynamoDbClient);
}
public function it_is_initializable()
{
$this->shouldHaveType(TraefikDynamoDb::class);
}
// NOTE: Cannot mock $this->initialize()
public function it_should_put_endpoint(
Settings $settings
) {
$settings->getDomain()
->shouldBeCalled()
->willReturn('phpspec.test');
$settings->getUserGuid()
->shouldBeCalled()
->willReturn(1000);
$this->config->get('pro')
->shouldBeCalled()
->willReturn([
'dynamodb_table_name' => 'phpspec'
]);
$this->dynamoDb->putItem(Argument::that(function ($args) {
return $args['TableName'] === 'phpspec';
}))
->shouldBeCalled()
->willReturn(true);
$this
->putEndpoint($settings)
->shouldReturn(true);
}
}
<?php
namespace Spec\Minds\Core\Pro\Domain;
use Minds\Common\Cookie;
use Minds\Common\Jwt;
use Minds\Core\Config;
use Minds\Core\Pro\Domain\Security;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class SecuritySpec extends ObjectBehavior
{
/** @var Cookie */
protected $cookie;
/** @var Jwt */
protected $jwt;
/** @var Config */
protected $config;
public function let(
Cookie $cookie,
Jwt $jwt,
Config $config
) {
$this->cookie = $cookie;
$this->jwt = $jwt;
$this->config = $config;
$this->beConstructedWith($cookie, $jwt, $config);
}
public function it_is_initializable()
{
$this->shouldHaveType(Security::class);
}
public function it_should_set_up()
{
$this->jwt->randomString()
->shouldBeCalled()
->willReturn('~random~');
$this->config->get('oauth')
->shouldBeCalled()
->willReturn([
'encryption_key' => 'phpspec'
]);
$this->jwt->setKey('phpspec')
->shouldBeCalled()
->willReturn($this->jwt);
$this->jwt->encode(Argument::type('array'))
->shouldBeCalled()
->willReturn('~encoded~');
$this->cookie->setName(Security::JWT_COOKIE_NAME)
->shouldBeCalled()
->willReturn($this->cookie);
$this->cookie->setName(Security::XSRF_COOKIE_NAME)
->shouldBeCalled()
->willReturn($this->cookie);
$this->cookie->setValue('~encoded~')
->shouldBeCalled()
->willReturn($this->cookie);
$this->cookie->setValue('~random~')
->shouldBeCalled()
->willReturn($this->cookie);
$this->cookie->setExpire(Argument::type('int'))
->shouldBeCalledTimes(2)
->willReturn($this->cookie);
$this->cookie->setPath('/')
->shouldBeCalledTimes(2)
->willReturn($this->cookie);
$this->cookie->setHttpOnly(false)
->shouldBeCalledTimes(2)
->willReturn($this->cookie);
$this->cookie->create()
->shouldBeCalledTimes(2)
->willReturn(true);
$this
->setUp('phpspec.test')
->shouldReturn('~encoded~');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment