Python
PyCharm 2021.3 EAP #3
The third PyCharm 2021.3 EAP build is out! Please give it a try, and don’t forget to share your feedback on Twitter (by mentioning @pycharm) or by reporting issues to our tracker! Important: PyCharm EAP Read more…
The third PyCharm 2021.3 EAP build is out! Please give it a try, and don’t forget to share your feedback on Twitter (by mentioning @pycharm) or by reporting issues to our tracker! Important: PyCharm EAP Read more…
Google’s Nest Hub 2nd Gen has a Thread radio built-in that will be updated in 2022 to enable Matter support. | Photo by Dan Seifert / The Verge Google gave a glimpse into how the Read more…
CFBP Director Rohit Chopra The Consumer Financial Protection Bureau has issued a series of information-gathering orders on the business practices of major digital payments systems. Orders were issued to Amazon, Apple, Facebook, Google, PayPal, and Read more…
Posted by Sameer Samat, Vice President, Product Management When we started Android and Google Play more than a decade ago, we made a bet that a free and open mobile ecosystem could compete with the Read more…
Illustration by Alex Castro / The Verge As regulatory pressure on the Play Store for Android increases, Google is once again making changes to its business structure. It has announced that more categories of apps Read more…
Image: Google Google’s Work Profile tool for Android, which lets you hide your work apps and data with the flip of a switch and keeps your personal phone use safe from your company, will be Read more…
Photo by Chris Welch / The Verge Tensions between Roku and Google spilled over to customers in a new blog posted by the streaming service on Thursday. After months of failed negotiations for Roku to Read more…
TCL, the company best known for its affordable Roku-equipped 4K TVs, has a new budget-oriented $399.99 5G tablet — the Tab Pro 5G. The device is available to order via Verizon’s online “Buy More, Save Read more…
[AdSense-A]
Mocking, faking; these might sound like intimidating words if you don't know what they are about, but once you do, you'll be able to improve your testing skills significantly.
Part of "the art of testing" is being able to test code in some level of isolation to make sure a test suite is trustworthy and versatile. These topics are so important that we actually made five or six videos on them in our Testing Laravel course.
In this post, I want to share three ways how you can deal with mocking and faking. Let's dive in!
Laravel has seven fakes â eight if you count time as well:
Bus
Event
HTTP
Mail
Notification
Queue
Storage
Time
Laravel fakes are useful because they are built-in ways to disable some of the core parts of the framework during testing while still being able to make assertions on them. Here's an example of using the Storage fake to assert whether a file would have been saved in the correct place if the code was run for real, outside of your test suite:
Storage::fake('public');
$post = BlogPost::factory()->create();
Storage::disk('public')
->assertExists("blog/{$post->slug}.png");
Laravel has built-in support for Mockery, a library that allows you to create mocks â fake implementations of a class â on the fly.
Here we create an example of an RssRepository, so that we won't perform an actual HTTP request, but instead return some dummy data:
$rss = $this->mock(
RssRepository::class,
function (MockInterface $mock) {
$mock
->shouldReceive('fetch')
->andReturn(collect([
new RssEntry(/* ⦠*/)
]));
}
);
You can imagine how using mocks can significantly impact the performance and reliability of your test suite.
Mockery can sometimes feel heavy or complex, depending on your use case. My personal preference is to use handcrafted mocks instead: a different implementation of an existing class, one that you register in Laravel's container when running tests. Here's an example:
class RssRepositoryFake extends RssRepository
{
public function fetch(string $url): Collection
{
return collect([
new RssEntry(/* ⦠*/),
]);
}
public static function setUp(): void
{
self::$urls = [];
app()->instance(
RssRepository::class,
new self(),
);
}
}
By cleverly using the service container, we can override our real RssRepository by one that doesn't actually perform any HTTP requests. If you're curious to learn more about them, you can check out our Testing Laravel course.
Leaks indicate the Pixel Fold may resemble the Samsung Galaxy Z Flip. | Image: Dan Seifert / The Verge During the “Pixel Fall Launch” event, Google formally launched the new Pixel 6 and Pixel 6 Read more…