Added tests
This commit is contained in:
1 parent
0c54185f1f
commit
6efcb252e1
7 files changed
+121
-4
No files matched your search
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
arch('it will not use debugging functions')
|
||||
->expect(['dd', 'dump', 'ray'])
|
||||
->each->not->toBeUsed();
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Mattitja\Cision\Cision;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
it('can fetch press releases from the RSS feed', function () {
|
||||
Http::fake([
|
||||
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/rss-press.xml')),
|
||||
]);
|
||||
|
||||
$cision = new Cision('test-company');
|
||||
$data = $cision->press();
|
||||
|
||||
expect($data)->toBeArray();
|
||||
expect($data)->toHaveKey('items');
|
||||
expect($data['items'])->not->toBeEmpty();
|
||||
|
||||
$item = $data['items'][0];
|
||||
expect($item)->toHaveKeys(['guid', 'title', 'description', 'link', 'created_at']);
|
||||
});
|
||||
|
||||
it('can fetch and parse full article content', function () {
|
||||
Http::fake([
|
||||
'news.cision.com/*' => Http::response(file_get_contents(__DIR__.'/Fixtures/article.html')),
|
||||
]);
|
||||
|
||||
$cision = new Cision();
|
||||
$content = $cision->fetchContent('https://news.cision.com/se/example/r/test,c123456');
|
||||
|
||||
expect($content)->toHaveKeys(['header', 'published_at', 'content']);
|
||||
expect($content['header'])->not->toBeEmpty();
|
||||
expect($content['content'])->toContain('<p');
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
<article>
|
||||
<div>
|
||||
<h1>Test Article Header</h1>
|
||||
<time pubdate="2025-07-04 07:55:00Z" datetime="2025-07-04 07:55:00Z">fre, jul 04, 2025 09:55 CET</time>
|
||||
<p><strong>Lead:</strong> This is a test article paragraph.</p>
|
||||
<p><em>Italic sentence.</em></p>
|
||||
<ul>
|
||||
<li><strong>Key:</strong> Value</li>
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>Test Press Releases</title>
|
||||
<item>
|
||||
<guid>test-guid</guid>
|
||||
<title>Test Press Title</title>
|
||||
<description>This is a test press release description.</description>
|
||||
<link>https://news.cision.com/se/example/r/test,c123456</link>
|
||||
<pubDate>Fri, 04 Jul 2025 07:55:00 GMT</pubDate>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Mattitja\Cision\Tests\TestCase;
|
||||
|
||||
uses(TestCase::class)->in(__DIR__);
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Mattitja\Cision\Tests;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Mattitja\Cision\CisionServiceProvider;
|
||||
use Orchestra\Testbench\TestCase as Orchestra;
|
||||
|
||||
class TestCase extends Orchestra
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Factory::guessFactoryNamesUsing(
|
||||
fn (string $modelName) => 'Mattitja\\Cision\\Database\\Factories\\'.class_basename($modelName).'Factory'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
CisionServiceProvider::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getEnvironmentSetUp($app)
|
||||
{
|
||||
config()->set('database.default', 'testing');
|
||||
|
||||
/*
|
||||
foreach (\Illuminate\Support\Facades\File::allFiles(__DIR__ . '/database/migrations') as $migration) {
|
||||
(include $migration->getRealPath())->up();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user