Skip to content

Commit

Permalink
Fix double urlencode sillyness
Browse files Browse the repository at this point in the history
  • Loading branch information
rjackson committed Sep 3, 2024
1 parent 3093f7d commit 1e80837
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/Helpers/TelegramHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function getId($level)
}

$id = $this->identifier ? " [" . $this->identifier . "] " : "";
return urlencode("$emoji $id ");
return "$emoji $id";
}

public function notify($level, $message)
Expand Down
100 changes: 50 additions & 50 deletions tests/unit/Helpers/TelegramHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,70 @@

class TelegramHelperTest extends TestCase
{
/** @var MockHandler */
protected $mock;
/** @var MockHandler */
protected $mock;

protected $container = [];
protected $container = [];

/** @var HandlerStack */
protected $handlerStack;
/** @var HandlerStack */
protected $handlerStack;

/** @var Client */
protected $client;
/** @var Client */
protected $client;

protected function setUp(): void
{
parent::setUp();
protected function setUp(): void
{
parent::setUp();

Config::set('telegram.bot_key', 'test-bot-key');
Config::set('telegram.bot_chat', 'test-chat-id');
Config::set('telegram.bot_key', 'test-bot-key');
Config::set('telegram.bot_chat', 'test-chat-id');

$this->mock = new MockHandler([]);
$this->mock = new MockHandler([]);

$history = Middleware::history($this->container);
$this->handlerStack = HandlerStack::create($this->mock);
$this->handlerStack->push($history);
$history = Middleware::history($this->container);
$this->handlerStack = HandlerStack::create($this->mock);
$this->handlerStack->push($history);

$this->client = new Client(['handler' => $this->handlerStack]);
}
$this->client = new Client(['handler' => $this->handlerStack]);
}

protected function tearDown(): void
{
Config::set('telegram.bot_key', null);
Config::set('telegram.bot_chat', null);
}
protected function tearDown(): void
{
Config::set('telegram.bot_key', null);
Config::set('telegram.bot_chat', null);
}

public function notifyDataProvider()
{
return [
[1, 'I am level "job"', '%E2%8F%B0++%5Btest-id%5D++I am level "job"'],
[2, 'I am level "log"', '%F0%9F%93%9C++%5Btest-id%5D++I am level "log"'],
[3, 'I am level "render"', '%F0%9F%91%80++%5Btest-id%5D++I am level "render"'],
[4, 'I am level "error"', '%F0%9F%9B%91++%5Btest-id%5D++I am level "error"'],
[5, 'I am level "warning"', '%E2%9A%A0%EF%B8%8F++%5Btest-id%5D++I am level "warning"'],
[99, 'I am an unrecognised level', '%E2%84%B9%EF%B8%8F++%5Btest-id%5D++I am an unrecognised level'],
];
}
public function notifyDataProvider()
{
return [
[1, 'I am level "job"', '⏰ [test-id] I am level "job"'],
[2, 'I am level "log"', '📜 [test-id] I am level "log"'],
[3, 'I am level "render"', '👀 [test-id] I am level "render"'],
[4, 'I am level "error"', '🛑 [test-id] I am level "error"'],
[5, 'I am level "warning"', '⚠️ [test-id] I am level "warning"'],
[99, 'I am an unrecognised level', 'ℹ️ [test-id] I am an unrecognised level'],
];
}

/**
* @dataProvider notifyDataProvider
*/
public function testNotify($level, $message, $encodedTextParam)
{
$this->mock->reset();
$this->mock->append(new Response(200, [], null));
/**
* @dataProvider notifyDataProvider
*/
public function testNotify($level, $message, $encodedTextParam)
{
$this->mock->reset();
$this->mock->append(new Response(200, [], null));


$telegramHelper = new TelegramHelper('test-id', $this->client);
$telegramHelper->notify($level, $message);
$telegramHelper = new TelegramHelper('test-id', $this->client);
$telegramHelper->notify($level, $message);

$this->assertCount(1, $this->container);
$this->assertCount(1, $this->container);

/** @var Request */
$request = $this->container[0]['request'];
$params = [];
parse_str($request->getUri()->getQuery(), $params);
/** @var Request */
$request = $this->container[0]['request'];
$params = [];
parse_str($request->getUri()->getQuery(), $params);

$this->assertEquals($encodedTextParam, $params['text']);
}
$this->assertEquals($encodedTextParam, $params['text']);
}
}

0 comments on commit 1e80837

Please sign in to comment.