Skip to content

Commit

Permalink
use Arr and Str helper classes (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pacha Cervantes authored Aug 10, 2021
1 parent 3552329 commit 6ab7279
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 43 deletions.
3 changes: 2 additions & 1 deletion src/Commands/DomainWhitelistingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Casperlaitw\LaravelFbMessenger\Commands;

use Casperlaitw\LaravelFbMessenger\Messages\DomainWhitelisting;
use Illuminate\Support\Arr;

/**
* Class DomainWhitelistingCommand
Expand Down Expand Up @@ -51,7 +52,7 @@ private function read()
{
$command = new DomainWhitelisting();
$command->setAction(DomainWhitelisting::TYPE_READ)->useGet();
$response = collect(array_get($this->handler->send($command)->getResponse(), 'data.0.whitelisted_domains', []))
$response = collect(Arr::get($this->handler->send($command)->getResponse(), 'data.0.whitelisted_domains', []))
->map(function ($item) {
return [$item];
});
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/HomeUrlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Casperlaitw\LaravelFbMessenger\Commands;

use Casperlaitw\LaravelFbMessenger\Messages\HomeUrl;
use Illuminate\Support\Arr;

/**
* Class HomeUrlCommand
Expand Down Expand Up @@ -49,7 +50,7 @@ private function read()
{
$command = new HomeUrl();
$command->setAction(HomeUrl::TYPE_READ)->useGet();
$response = collect(array_get($this->handler->send($command)->getResponse(), 'data.0.home_url', []))
$response = collect(Arr::get($this->handler->send($command)->getResponse(), 'data.0.home_url', []))
->map(function ($item) {
return [$item];
});
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/MessengerCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Casperlaitw\LaravelFbMessenger\Commands;

use Casperlaitw\LaravelFbMessenger\Messages\MessengerCode;
use Illuminate\Support\Arr;

class MessengerCodeCommand extends BaseCommand
{
Expand Down Expand Up @@ -35,6 +36,6 @@ public function handle()
$message->setRef($ref);
}

$this->comment(array_get($this->handler->send($message), 'uri'));
$this->comment(Arr::get($this->handler->send($message), 'uri'));
}
}
7 changes: 4 additions & 3 deletions src/Contracts/Debug/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Exception;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Support\Arr;

class Handler implements ExceptionHandler
{
Expand Down Expand Up @@ -61,9 +62,9 @@ public function render($request, Exception $e)
'message' => $e->getMessage(),
'trace' => collect($e->getTrace())->map(function ($item) {
return [
'file' => array_get($item, 'file'),
'line' => array_get($item, 'line'),
'method' => array_get($item, 'function'),
'file' => Arr::get($item, 'file'),
'line' => Arr::get($item, 'line'),
'method' => Arr::get($item, 'function'),
];
})->toArray(),
];
Expand Down
4 changes: 3 additions & 1 deletion src/Contracts/HandleMessageResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Casperlaitw\LaravelFbMessenger\Contracts;

use Illuminate\Support\Arr;

/**
* Class HandleMessageResponse
* @package Casperlaitw\LaravelFbMessenger\Contracts
Expand Down Expand Up @@ -37,7 +39,7 @@ public function getResponse()
if (!empty($this->response['error'])) {
return $this->handleError($this->response['error']);
}
return array_get($this->response, 'result', $this->response);
return Arr::get($this->response, 'result', $this->response);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Collections/ButtonCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Casperlaitw\LaravelFbMessenger\Exceptions\OnlyUseByItselfException;
use Casperlaitw\LaravelFbMessenger\Exceptions\ValidatorStructureException;
use Casperlaitw\LaravelFbMessenger\Messages\Button;
use Illuminate\Support\Str;
use Faker\Factory;
use Mockery as m;

Expand Down Expand Up @@ -54,7 +55,7 @@ public function test_add_call_button()
{
$fake = Factory::create();
$collection = new ButtonCollection();
$title = str_random();
$title = Str::random();
$phone = $fake->phoneNumber;
$collection->addCallButton($title, $phone);

Expand All @@ -73,7 +74,7 @@ public function test_add_share_button()

public function test_add_account_link_button()
{
$url = str_random();
$url = Str::random();
$collection = new ButtonCollection();
$collection->addAccountLinkButton($url);
$expected = new Button(Button::TYPE_ACCOUNT_LINK, null, $url);
Expand Down
3 changes: 2 additions & 1 deletion tests/Contracts/BotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Casperlaitw\LaravelFbMessenger\Messages\MessengerCode;
use Casperlaitw\LaravelFbMessenger\Messages\User;
use Illuminate\Broadcasting\BroadcastException;
use Illuminate\Support\Str;
use Illuminate\Events\Dispatcher;
use Mockery as m;

Expand All @@ -24,7 +25,7 @@ protected function setUp()

public function test_send_success()
{
$message = new Greeting(['locale' => 'default', 'text' => str_random()]);
$message = new Greeting(['locale' => 'default', 'text' => Str::random()]);
$this->bot->setSecret('test_app_secret');
$this->bot->send($message);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Contracts/Debug/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Casperlaitw\LaravelFbMessenger\Contracts\Debug\Debug;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Arr;
use Mockery as m;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -56,6 +57,6 @@ public function test_render()

$actual = $this->getPrivateProperty(Handler::class, 'debug')->getValue($this->handler);
$this->assertEquals(500, $actual->getStatus());
$this->assertEquals('ERROR', array_get($actual->getResponse(), 'message'));
$this->assertEquals('ERROR', Arr::get($actual->getResponse(), 'message'));
}
}
5 changes: 3 additions & 2 deletions tests/Contracts/Messages/AttachmentTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
use Casperlaitw\LaravelFbMessenger\Contracts\Messages\Attachment;
use Casperlaitw\LaravelFbMessenger\Exceptions\InvalidTypeException;
use Illuminate\Support\Str;
use Faker\Factory;
use Mockery as m;

Expand All @@ -22,7 +23,7 @@ protected function setUp()
{
parent::setUp();
$this->faker = Factory::create();
$sender = str_random();
$sender = Str::random();
$type = Attachment::TYPE_IMAGE;
$image = $this->faker->url;
$this->attachment = new AttachmentStub($sender, $type, ['url' => $image]);
Expand Down Expand Up @@ -57,7 +58,7 @@ public function test_disable_reuse()

public function test_set_attachment_id()
{
$id = str_random();
$id = Str::random();
$this->attachment->setAttachmentId($id);

$this->assertEquals(['attachment_id' => $id], $this->attachment->getPayload());
Expand Down
5 changes: 3 additions & 2 deletions tests/Contracts/Messages/StructuredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Casperlaitw\LaravelFbMessenger\Messages\Button;
use Casperlaitw\LaravelFbMessenger\Messages\ButtonTemplate;
use Illuminate\Support\Str;
use Mockery as m;

/**
Expand All @@ -13,13 +14,13 @@ class StructuredTest extends TestCase
{
public function test_call_method()
{
$button = new ButtonTemplate(str_random(), str_random());
$button = new ButtonTemplate(Str::random(), Str::random());
$this->assertTrue($button->validator($this->getMessageButtonMock()));
}

public function test_non_collection_method()
{
$button = new ButtonTemplate(str_random(), str_random());
$button = new ButtonTemplate(Str::random(), Str::random());
$button->getError();
}

Expand Down
5 changes: 3 additions & 2 deletions tests/Controllers/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Str;
use Mockery as m;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand All @@ -20,7 +21,7 @@ class WebhookControllerTest extends TestCase
public function test_index_token_verify_pass_response_challenge_token()
{
$verifyToken = 'MY_VERIFY_TOKEN';
$challenge = str_random();
$challenge = Str::random();
$request = m::mock(Request::class)
->shouldReceive('get')
->with('hub_mode')
Expand Down Expand Up @@ -55,7 +56,7 @@ public function test_index_and_abort()
->getMock();
$config = m::mock(Repository::class)
->shouldReceive('get')
->andReturn(str_random())
->andReturn(Str::random())
->getMock();
$debug = m::mock(Debug::class);

Expand Down
3 changes: 2 additions & 1 deletion tests/Events/BroadcastTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Casperlaitw\LaravelFbMessenger\Events\Broadcast;
use Illuminate\Support\Str;

/**
* Created by PhpStorm.
Expand All @@ -20,7 +21,7 @@ public function setUp()
{
parent::setUp();

$this->id = $this->response = $this->code = $this->webhook = $this->request = str_random();
$this->id = $this->response = $this->code = $this->webhook = $this->request = Str::random();
$this->broadcast = new Broadcast($this->id, $this->webhook, $this->request, $this->response, $this->code);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Messages/AudioTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Casperlaitw\LaravelFbMessenger\Messages\Audio;
use Illuminate\Support\Str;
use Faker\Factory;

/**
Expand All @@ -13,7 +14,7 @@ class AudioTest extends TestCase
public function test_to_data()
{
$faker = Factory::create();
$sender = str_random();
$sender = Str::random();
$url = $faker->url;

$actual = new Audio($sender, $url);
Expand Down
3 changes: 2 additions & 1 deletion tests/Messages/ButtonTemplateTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Casperlaitw\LaravelFbMessenger\Messages\ButtonTemplate;
use Illuminate\Support\Str;
use Mockery as m;
use pimax\Messages\StructuredMessage;

Expand All @@ -19,7 +20,7 @@ class ButtonTemplateTest extends TestCase

public function setUp()
{
$this->sender = str_random();
$this->sender = Str::random();
$this->text = 'abc';
$this->case = new ButtonTemplate($this->sender, $this->text);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Messages/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use Casperlaitw\LaravelFbMessenger\Collections\ButtonCollection;
use Casperlaitw\LaravelFbMessenger\Messages\Element;
use Casperlaitw\LaravelFbMessenger\Messages\UrlButton;
use Illuminate\Support\Str;

/**
* User: casperlai
Expand All @@ -13,13 +14,13 @@ class ElementTest extends TestCase
{
public function test_button()
{
$element = new Element(str_random(), str_random());
$element = new Element(Str::random(), Str::random());
$this->assertInstanceOf(ButtonCollection::class, $element->buttons());
}

public function test_default_action()
{
$element = new Element(str_random(), str_random());
$element = new Element(Str::random(), Str::random());
$element->setDefaultAction(new UrlButton('title', 'url'));

$this->assertArraySubset([
Expand Down
3 changes: 2 additions & 1 deletion tests/Messages/FileTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Casperlaitw\LaravelFbMessenger\Messages\File;
use Illuminate\Support\Str;
use Faker\Factory;

/**
Expand All @@ -12,7 +13,7 @@ class FileTest extends TestCase
public function test_to_data()
{
$faker = Factory::create();
$sender = str_random();
$sender = Str::random();
$url = $faker->url;

$actual = new File($sender, $url);
Expand Down
3 changes: 2 additions & 1 deletion tests/Messages/GenericTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Casperlaitw\LaravelFbMessenger\Messages\Element;
use Casperlaitw\LaravelFbMessenger\Messages\GenericTemplate;
use Illuminate\Support\Str;
use pimax\Messages\StructuredMessage;

/**
Expand All @@ -17,7 +18,7 @@ class GenericTemplateTest extends TestCase

public function setUp()
{
$this->sender = str_random();
$this->sender = Str::random();
$this->case = [
new Element('title1', 'description1'),
new Element('title2', 'description2')
Expand Down
3 changes: 2 additions & 1 deletion tests/Messages/GreetingTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Casperlaitw\LaravelFbMessenger\Messages\Greeting;
use Illuminate\Support\Str;

/**
* User: casperlai
Expand All @@ -10,7 +11,7 @@ class GreetingTest extends TestCase
{
public function test_to_data()
{
$greetingText = str_random();
$greetingText = Str::random();
$expected = [
'greeting' => [
[
Expand Down
5 changes: 3 additions & 2 deletions tests/Messages/ImageTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Casperlaitw\LaravelFbMessenger\Messages\Image;
use Illuminate\Support\Str;

/**
* User: casperlai
Expand All @@ -10,8 +11,8 @@ class ImageTest extends TestCase
{
public function test_to_data()
{
$sender = str_random();
$image = str_random();
$sender = Str::random();
$image = Str::random();
$expected = [
'recipient' => [
'id' => $sender,
Expand Down
3 changes: 2 additions & 1 deletion tests/Messages/ListTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Casperlaitw\LaravelFbMessenger\Messages\Button;
use Casperlaitw\LaravelFbMessenger\Messages\Element;
use Casperlaitw\LaravelFbMessenger\Messages\ListTemplate;
use Illuminate\Support\Str;

/**
* Created by PhpStorm.
Expand All @@ -18,7 +19,7 @@ class ListTemplateTest extends TestCase

public function setUp()
{
$this->sender = str_random();
$this->sender = Str::random();
$this->case = [
new Element('title1', 'description1', 'image1'),
new Element('title2', 'description2', 'image2'),
Expand Down
3 changes: 2 additions & 1 deletion tests/Messages/QuickReplyTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Casperlaitw\LaravelFbMessenger\Messages\QuickReply;
use Illuminate\Support\Str;

/**
* Created by PhpStorm.
Expand Down Expand Up @@ -36,7 +37,7 @@ public function test_set_image()
{
$title = 'Red';
$payload = 'PAYLOAD_RED';
$image = str_random();
$image = Str::random();

$expected = [
'content_type' => 'text',
Expand Down
Loading

0 comments on commit 6ab7279

Please sign in to comment.