Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
symfony_2504
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lech Sawoń
symfony_2504
Commits
3d55dc4e
Commit
3d55dc4e
authored
Oct 28, 2021
by
Lech Sawon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unit test example
parent
ff4cf5b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
264 additions
and
6 deletions
+264
-6
AddReservation.php
src/Service/Reservation/AddReservation.php
+1
-5
ApiExceptionSubscriber.php
src/Subscriber/ApiExceptionSubscriber.php
+0
-1
AddReservationTest.php
tests/AddReservationTest.php
+33
-0
EntityManagerSpy.php
tests/EntityManagerSpy.php
+230
-0
No files found.
src/Service/Reservation/AddReservation.php
View file @
3d55dc4e
...
@@ -6,18 +6,14 @@ namespace App\Service\Reservation;
...
@@ -6,18 +6,14 @@ namespace App\Service\Reservation;
use
App\Entity\Reservation
;
use
App\Entity\Reservation
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Psr\Log\LoggerInterface
;
final
class
AddReservation
final
class
AddReservation
{
{
private
EntityManagerInterface
$manager
;
private
EntityManagerInterface
$manager
;
private
LoggerInterface
$logger
;
public
function
__construct
(
EntityManagerInterface
$manager
)
public
function
__construct
(
EntityManagerInterface
$manager
,
LoggerInterface
$logger
)
{
{
$this
->
manager
=
$manager
;
$this
->
manager
=
$manager
;
$this
->
logger
=
$logger
;
}
}
...
...
src/Subscriber/ApiExceptionSubscriber.php
View file @
3d55dc4e
...
@@ -64,7 +64,6 @@ final class ApiExceptionSubscriber implements EventSubscriberInterface
...
@@ -64,7 +64,6 @@ final class ApiExceptionSubscriber implements EventSubscriberInterface
$event
->
setResponse
(
$response
);
$event
->
setResponse
(
$response
);
}
}
if
(
$exception
instanceof
NotFoundHttpException
)
{
if
(
$exception
instanceof
NotFoundHttpException
)
{
$response
=
new
JsonResponse
(
$response
=
new
JsonResponse
(
...
...
tests/AddReservationTest.php
0 → 100644
View file @
3d55dc4e
<?php
declare
(
strict_types
=
1
);
namespace
App\Tests
;
use
App\Entity\Reservation
;
use
App\Service\Reservation\AddReservation
;
use
PHPUnit\Framework\TestCase
;
//uproszczony przykład testu jednstkowego
final
class
AddReservationTest
extends
TestCase
{
public
function
testTest
()
:
void
{
//przygotwanie środowiska (given)
$emSpy
=
new
EntityManagerSpy
();
$service
=
new
AddReservation
(
$emSpy
);
$reservation
=
new
Reservation
();
//wykonanie akcji (then)
$service
->
add
(
$reservation
);
//sprawdzenie warunków
self
::
assertEquals
(
1
,
$emSpy
->
getFlushCount
());
self
::
assertEquals
(
$reservation
,
$emSpy
->
getPersisted
()[
0
]);
self
::
assertSame
(
$reservation
,
$emSpy
->
getPersisted
()[
0
]);
}
}
tests/EntityManagerSpy.php
0 → 100644
View file @
3d55dc4e
<?php
declare
(
strict_types
=
1
);
namespace
App\Tests
;
use
Doctrine\ORM\EntityManagerInterface
;
//Nie powinniśmy rubić zaślepki dla nie swojego interfacu
//lepiej by bylo funckje zapisu umieścić w repository
// i zaślepiać interface tego repository
final
class
EntityManagerSpy
implements
EntityManagerInterface
{
private
array
$persisted
=
[];
private
int
$flushCount
=
0
;
public
function
getPersisted
()
:
array
{
return
$this
->
persisted
;
}
public
function
getFlushCount
()
:
int
{
return
$this
->
flushCount
;
}
public
function
persist
(
$object
)
{
$this
->
persisted
[]
=
$object
;
}
public
function
flush
()
{
$this
->
flushCount
++
;
}
public
function
getRepository
(
$className
)
{
// TODO: Implement getRepository() method.
}
public
function
getCache
()
{
// TODO: Implement getCache() method.
}
public
function
getConnection
()
{
// TODO: Implement getConnection() method.
}
public
function
getExpressionBuilder
()
{
// TODO: Implement getExpressionBuilder() method.
}
public
function
beginTransaction
()
{
// TODO: Implement beginTransaction() method.
}
public
function
transactional
(
$func
)
{
// TODO: Implement transactional() method.
}
public
function
commit
()
{
// TODO: Implement commit() method.
}
public
function
rollback
()
{
// TODO: Implement rollback() method.
}
public
function
createQuery
(
$dql
=
''
)
{
// TODO: Implement createQuery() method.
}
public
function
createNamedQuery
(
$name
)
{
// TODO: Implement createNamedQuery() method.
}
public
function
createNativeQuery
(
$sql
,
\Doctrine\ORM\Query\ResultSetMapping
$rsm
)
{
// TODO: Implement createNativeQuery() method.
}
public
function
createNamedNativeQuery
(
$name
)
{
// TODO: Implement createNamedNativeQuery() method.
}
public
function
createQueryBuilder
()
{
// TODO: Implement createQueryBuilder() method.
}
public
function
getReference
(
$entityName
,
$id
)
{
// TODO: Implement getReference() method.
}
public
function
getPartialReference
(
$entityName
,
$identifier
)
{
// TODO: Implement getPartialReference() method.
}
public
function
close
()
{
// TODO: Implement close() method.
}
public
function
copy
(
$entity
,
$deep
=
false
)
{
// TODO: Implement copy() method.
}
public
function
lock
(
$entity
,
$lockMode
,
$lockVersion
=
null
)
{
// TODO: Implement lock() method.
}
public
function
getEventManager
()
{
// TODO: Implement getEventManager() method.
}
public
function
getConfiguration
()
{
// TODO: Implement getConfiguration() method.
}
public
function
isOpen
()
{
// TODO: Implement isOpen() method.
}
public
function
getUnitOfWork
()
{
// TODO: Implement getUnitOfWork() method.
}
public
function
getHydrator
(
$hydrationMode
)
{
// TODO: Implement getHydrator() method.
}
public
function
newHydrator
(
$hydrationMode
)
{
// TODO: Implement newHydrator() method.
}
public
function
getProxyFactory
()
{
// TODO: Implement getProxyFactory() method.
}
public
function
getFilters
()
{
// TODO: Implement getFilters() method.
}
public
function
isFiltersStateClean
()
{
// TODO: Implement isFiltersStateClean() method.
}
public
function
hasFilters
()
{
// TODO: Implement hasFilters() method.
}
public
function
getClassMetadata
(
$className
)
{
// TODO: Implement getClassMetadata() method.
}
public
function
find
(
$className
,
$id
)
{
// TODO: Implement find() method.
}
public
function
remove
(
$object
)
{
// TODO: Implement remove() method.
}
public
function
merge
(
$object
)
{
// TODO: Implement merge() method.
}
public
function
clear
(
$objectName
=
null
)
{
// TODO: Implement clear() method.
}
public
function
detach
(
$object
)
{
// TODO: Implement detach() method.
}
public
function
refresh
(
$object
)
{
// TODO: Implement refresh() method.
}
public
function
initializeObject
(
$obj
)
{
// TODO: Implement initializeObject() method.
}
public
function
contains
(
$object
)
{
// TODO: Implement contains() method.
}
public
function
__call
(
$name
,
$arguments
)
{
// TODO: Implement @method Mapping\ClassMetadataFactory getMetadataFactory()
// TODO: Implement @method mixed wrapInTransaction(callable $func)
}
public
function
getMetadataFactory
(){}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment