The Clean Architecture in php


use Evenement\EventEmitterInterface; use



Download 2,26 Mb.
Pdf ko'rish
bet144/179
Sana24.06.2021
Hajmi2,26 Mb.
#100337
1   ...   140   141   142   143   144   145   146   147   ...   179
Bog'liq
The-Clean-Architecture-in-PHP-Kristopher-Wilson

use
Evenement\EventEmitterInterface;
use
Peridot\Plugin\Prophecy\ProphecyPlugin;
use
Peridot\Plugin\Watcher\WatcherPlugin;
return function
(EventEmitterInterface
$emitter
) {
$watcher
=
new
WatcherPlugin(
$emitter
);
$watcher
->
track
(__DIR__
.
'/src'
);
new
ProphecyPlugin(
$emitter
);
};
Now, we can write a
beforeEach()
block that will get executed before each test to build us a
mocked
OrderRepositoryInterface
:
// specs/domain/service/invoice-factory.spec.php
$repo
=
'CleanPhp\Invoicer\Domain\Repository\OrderRepositoryInterface'
;
describe(
'InvoicingService'
,
function
() {
describe(
'->generateInvoices()'
,
function
() {
beforeEach(
function
() {
$this
->
repository
=
$this
->
getProphet
()
->
prophesize
(
$repo
);
});
// ...
});
});
When we need it,
$this->repository
will hold an instance of a mocked repository. Now we can
finish our first test:


Building Our Domain
114
it(
'should query the repository for uninvoiced Orders'
,
function
() {
$this
->
repository
->
getUninvoicedOrders
()
->
shouldBeCalled
();
$service
=
new
InvoicingService(
$this
->
repository
->
reveal
());
$service
->
generateInvoices
();
});
We’re testing here that when we call the
generateInvoices()
method, we should expect that
the
InvoicingService
will make a call to the
getUninvoicedOrders()
method of
OrderRepositoryInterface
.
We’ll also want to add an
afterEach()
block to tell Prophecy to check the assertions it makes,
like
shouldBeCalled()
as otherwise it won’t know exactly when it’s safe to check that assertion.
We can do it in an
afterEach()
just to make it easy on us, but really we could add it anywhere
within the test:
afterEach(
function
() {
$this
->
getProphet
()
->
checkPrediections
();
});
Of course, without any code, these tests should be failing, so let’s go fix that:
// src/Domain/Service/InvoicingService.php
namespace
CleanPhp\Invoicer\Domain\Service;
use
CleanPhp\Invoicer\Domain\Repository\OrderRepositoryInterface;

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   140   141   142   143   144   145   146   147   ...   179




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish