Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Fix tests (#8)
Browse files Browse the repository at this point in the history
* Fix tests

* Fix style
  • Loading branch information
inverse authored Jul 24, 2019
1 parent e77028a commit 62636bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
23 changes: 19 additions & 4 deletions src/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

class Region
{
const CN = 'cn';
const EU = 'eu';
const US = 'us';
private const CN = 'cn';
private const EU = 'eu';
private const US = 'us';

const VALID_REGIONS = [
private const VALID_REGIONS = [
self::CN,
self::EU,
self::US,
Expand Down Expand Up @@ -52,4 +52,19 @@ public static function createDefault(): self
{
return new self(self::US);
}

public static function createUS(): self
{
return new self(self::US);
}

public static function createCN(): self
{
return new self(self::CN);
}

public static function createEU(): self
{
return new self(self::EU);
}
}
29 changes: 8 additions & 21 deletions tests/Unit/RegionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,40 @@

namespace Tests\Unit\Inverse\TuyaClient;

use InvalidArgumentException;
use Inverse\TuyaClient\Region;
use Inverse\TuyaClient\Token;
use PHPUnit\Framework\TestCase;

class RegionTest extends TestCase
{
/**
* @param Token $token
* @param Token $token
* @param Region $expected
* @dataProvider fromAccessTokenProvider
*/
public function testFromAccessToken(Token $token): void
public function testFromAccessToken(Token $token, Region $expected): void
{
$this->doesNotPerformAssertions();
Region::fromAccessToken($token);
$this->assertEquals($expected, Region::fromAccessToken($token));
}

public function fromAccessTokenProvider(): array
{
return [
'EU' => [
new Token('EU123456', '', 0),
Region::createEU(),
],
'China' => [
new Token('AY123456', '', 0),
Region::createCN(),
],
];
}

/**
* @param Token $token
* @dataProvider fromAccessTokenProviderInvalid
*/
public function testFromAccessTokenInvalid(Token $token): void
{
$this->expectException(InvalidArgumentException::class);
Region::fromAccessToken($token);
}

public function fromAccessTokenProviderInvalid(): array
{
return [
'Empty' => [
new Token('', '', 0),
Region::createUS(),
],
'Unmapped' => [
new Token('DJHFHD3847', '', 0),
Region::createUS(),
],
];
}
Expand Down

0 comments on commit 62636bf

Please sign in to comment.