The Clean Architecture in php


class CustomerRepository



Download 2,26 Mb.
Pdf ko'rish
bet83/179
Sana24.06.2021
Hajmi2,26 Mb.
#100337
1   ...   79   80   81   82   83   84   85   86   ...   179
Bog'liq
The-Clean-Architecture-in-PHP-Kristopher-Wilson

class
CustomerRepository
implements
CustomerRepositoryInterface {
public function
getById
(
$id
) {
// get and return the customer...
}
}
The
CustomerRepository
provides the implementation of the
getById()
method and fulfills the
requirements of the interface.
When we want to test this controller now, we can instead use a mock instance of
CustomerRepositoryInterface
:
class
MockCustomerRepository
implements
CustomerRepositoryInterface {
public function
getById
(
$id
) {
if
(
$id
== 1001
) {
return
(
new
Customer())
->
setId
(
1
)
->
setName
(
'Customer #1001'
);
}
}
}
While this may not be the greatest code (and using a mocking library like
Mockery¹⁹
or the
mocking utilities provided by PHPUnit would be better²⁰
), we can nevertheless pass this in to
CustomersController
to fulfill the
CustomerRepositoryInterface
type hint. Now the controller
is being tested in isolation, without the specific configuration and dependencies of the real
CustomerRepository
.
The
CustomersController
really doesn’t care what object you end up injecting it with. So long
as that object meets the required interface (and it will, otherwise a fatal error will be thrown),
the controller should function just the same. This also assumes, of course, that the dependencies
being injected actually work and return the data they should.

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   79   80   81   82   83   84   85   86   ...   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