Skip to content

Commit

Permalink
Update client class
Browse files Browse the repository at this point in the history
  • Loading branch information
ssitdikov committed Jan 3, 2018
1 parent 9a62d1f commit d8f0067
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Client/TelegraphClient.php
Expand Up @@ -31,6 +31,11 @@ public function __construct(Client $client = null)
$this->client = $client;
}

public function getClient()
{
return $this->client;
}

public function createAccount(CreateAccountRequest $request): Account
{
return $this->doRequest($request);
Expand Down
21 changes: 21 additions & 0 deletions src/Type/ContentType/NodeElementType.php
@@ -0,0 +1,21 @@
<?php

namespace SSitdikov\TelegraphAPI\Type\ContentType;

class NodeElementType extends AbstractNodeElementType
{
public function setTag($tag)
{
$this->tag = $tag;
}

public function setChildren($children)
{
$this->children = $children;
}

public function addChildren($child)
{
$this->children[] = $child;
}
}
13 changes: 13 additions & 0 deletions tests/Client/TelegraphClientTest.php
Expand Up @@ -3,6 +3,10 @@
namespace SSitdikov\TelegraphAPI\Tests\Client;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -781,4 +785,13 @@ public function getViewsError()
);
}

/**
* @test
*/
public function getClient()
{
$telegraph = new TelegraphClient();
$this->assertEquals(Client::class, get_class($telegraph->getClient()));
}

}
20 changes: 20 additions & 0 deletions tests/Page/ContentTypesTest.php
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\TestCase;
use SSitdikov\TelegraphAPI\Type\ContentType\ImageType;
use SSitdikov\TelegraphAPI\Type\ContentType\LinkType;
use SSitdikov\TelegraphAPI\Type\ContentType\NodeElementType;
use SSitdikov\TelegraphAPI\Type\ContentType\ParagraphType;
use SSitdikov\TelegraphAPI\Type\ContentType\YoutubeType;

Expand Down Expand Up @@ -130,4 +131,23 @@ public function youtubeType()
json_encode($youtube)
);
}

/**
* @test
*/
public function nodeElementType()
{
$node = new NodeElementType();
$node->setTag('em');
$node->setChildren(['test']);
$node->addChildren('rest');

$this->assertJson(json_encode([
'tag' => 'em',
'children' => [
'test', 'rest'
]
]),
json_encode($node));
}
}

0 comments on commit d8f0067

Please sign in to comment.