-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made changes to upgrade the libraries #12
Changes from 10 commits
033f7d2
537ba16
062c233
299a26b
765f9b1
ef1e8f1
8e5cde2
2c77ba7
cbfd186
9d7a325
93f25f4
c44b78b
b118296
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
<?php /** @noinspection ALL */ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Model Factories | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Here you may define all of your model factories. Model factories give | ||
| you a convenient way to create models for testing and seeding your | ||
| database. Just tell the factory how a default model should look. | ||
| | ||
*/ | ||
namespace Database\Factories\Joskfg\LaravelIntelligentScraper\Scraper\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Joskfg\LaravelIntelligentScraper\Scraper\Models\ScrapedDataset; | ||
|
||
/* @var \Illuminate\Database\Eloquent\Factory $factory */ | ||
$factory->define(ScrapedDataset::class, function (Faker\Generator $faker) { | ||
$url = $faker->url . $faker->randomDigit; | ||
class ScrapedDatasetFactory extends Factory | ||
{ | ||
protected $model = ScrapedDataset::class; | ||
|
||
return [ | ||
'url_hash' => hash('sha256', $url), | ||
'url' => $url, | ||
'type' => 'post', | ||
'variant' => $faker->sha1, | ||
'fields' => [ | ||
[ | ||
'key' => 'title', | ||
'value' => $faker->word, | ||
'found' => $faker->boolean(), | ||
public function definition() | ||
{ | ||
$url = $this->faker->url . $this->faker->randomDigit; | ||
return [ | ||
'url_hash' => hash('sha256', $url), | ||
'url' => $url, | ||
'type' => 'post', | ||
'variant' => $this->faker->sha1, | ||
'fields' => [ | ||
[ | ||
'key' => 'title', | ||
'value' => $this->faker->word, | ||
'found' => $this->faker->boolean(), | ||
], | ||
[ | ||
'key' => 'author', | ||
'value' => $this->faker->word, | ||
'found' => $this->faker->boolean(), | ||
], | ||
], | ||
[ | ||
'key' => 'author', | ||
'value' => $faker->word, | ||
'found' => $faker->boolean(), | ||
], | ||
], | ||
]; | ||
}); | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Joskfg\LaravelIntelligentScraper\Scraper\Listeners; | ||
|
||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\Facades\Log; | ||
use Joskfg\LaravelIntelligentScraper\Scraper\Application\XpathFinder; | ||
use Joskfg\LaravelIntelligentScraper\Scraper\Entities\ScrapedData; | ||
|
@@ -37,6 +38,8 @@ public function setUp(): void | |
|
||
Log::spy(); | ||
|
||
Event::fake(); | ||
|
||
$this->config = Mockery::mock(Configuration::class); | ||
$this->xpathFinder = Mockery::mock(XpathFinder::class); | ||
$this->url = ':scrape-url:'; | ||
|
@@ -65,7 +68,7 @@ public function whenCannotBeCalculatedItShouldThrowAnException(): void | |
Log::getFacadeRoot() | ||
); | ||
|
||
$this->expectsEvents(ScrapeFailed::class); | ||
Event::assertNotDispatched(ScrapeFailed::class); | ||
|
||
$scrapeRequest = new ScrapeRequest($this->url, $this->type); | ||
$configureScraper->handle(new InvalidConfiguration($scrapeRequest)); | ||
|
@@ -112,18 +115,20 @@ public function whenIsCalculatedItShouldReturnExtractedDataAndStoreTheNewConfig( | |
Log::getFacadeRoot() | ||
); | ||
|
||
$this->expectsEvents(Scraped::class); | ||
// $this->expectsEvents(Scraped::class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid to leave dead code as comments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
||
Event::assertNotDispatched(Scraped::class); | ||
$configureScraper->handle(new InvalidConfiguration(new ScrapeRequest($this->url, $this->type))); | ||
|
||
/** @var Scraped $event */ | ||
$event = collect($this->firedEvents)->filter(function ($event): bool { | ||
$firedEvents = collect(Event::dispatched(Scraped::class)); | ||
$event = $firedEvents->each(function ($event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of these iterations? The same happens in the next test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unwanted code. Removed it. |
||
$class = Scraped::class; | ||
|
||
return $event instanceof $class; | ||
})->first(); | ||
self::assertEquals( | ||
}); | ||
|
||
self::assertSame( | ||
$scrapedData, | ||
$event->scrapedData | ||
$event[0][0]->scrapedData | ||
); | ||
|
||
$this->assertDatabaseHas( | ||
|
@@ -209,7 +214,8 @@ public function whenTheIdStoreIsNotAvailableItShouldThrowAnUnexpectedValueExcept | |
Log::shouldReceive('debug'); | ||
Log::shouldReceive('error') | ||
->with("Error scraping ':scrape-url:'", ['message' => ':error:']); | ||
$this->expectsEvents(ScrapeFailed::class); | ||
|
||
Event::assertNotDispatched(ScrapeFailed::class); | ||
|
||
$configureScraper = new ConfigureScraper( | ||
$this->config, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should expect the event to be dispatched. This issue is repeated bellow a few times and in other tests.