1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96:
<?php
namespace League\OAuth2\Client\Test\Grant;
use League\OAuth2\Client\Grant\GrantFactory;
use League\OAuth2\Client\Grant\AbstractGrant;
use League\OAuth2\Client\Grant\Exception\InvalidGrantException;
use League\OAuth2\Client\Test\Grant\Fake as MockGrant;
use PHPUnit\Framework\TestCase;
class GrantFactoryTest extends TestCase
{
protected $factory;
protected function setUp()
{
$this->factory = new GrantFactory();
}
public function testGetGrantDefaults($name)
{
$grant = $this->factory->getGrant($name);
$this->assertInstanceOf(AbstractGrant::class, $grant);
}
public function providerGetGrantDefaults()
{
return [
'authorization_code' => ['authorization_code'],
'client_credentials' => ['client_credentials'],
'password' => ['password'],
'refresh_token' => ['refresh_token'],
];
}
public function testGetInvalidGrantFails()
{
$this->factory->getGrant('invalid');
}
public function testSetGrantReplaceDefault()
{
$mock = new MockGrant();
$factory = new GrantFactory();
$factory->setGrant('password', $mock);
$grant = $factory->getGrant('password');
$this->assertSame($mock, $grant);
}
public function testSetGrantCustom()
{
$mock = new MockGrant();
$factory = new GrantFactory();
$factory->setGrant('fake', $mock);
$grant = $factory->getGrant('fake');
$this->assertSame($mock, $grant);
}
public function testIsGrant()
{
$grant = $this->factory->getGrant('password');
$this->assertTrue($this->factory->isGrant($grant));
$this->assertFalse($this->factory->isGrant('stdClass'));
}
public function testCheckGrant()
{
$grant = $this->factory->getGrant('password');
$this->assertNull($this->factory->checkGrant($grant));
}
public function testCheckGrantInvalidFails()
{
$this->factory->checkGrant('stdClass');
}
}