Skip to content

Commit b5471bd

Browse files
authored
Merge pull request #62 from DirectoryTree/fakes
Fakes
2 parents 4688de8 + 8b947d9 commit b5471bd

18 files changed

+1542
-282
lines changed

src/FolderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function is(FolderInterface $folder): bool;
3939
/**
4040
* Begin querying for messages.
4141
*/
42-
public function messages(): MessageQuery;
42+
public function messages(): MessageQueryInterface;
4343

4444
/**
4545
* Begin idling on the current folder.

src/FolderRepository.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,35 @@ public function __construct(
1717
/**
1818
* {@inheritDoc}
1919
*/
20-
public function find(string $folder): ?FolderInterface
20+
public function find(string $path): ?FolderInterface
2121
{
22-
return $this->get($folder)->first();
22+
return $this->get($path)->first();
2323
}
2424

2525
/**
2626
* {@inheritDoc}
2727
*/
28-
public function findOrFail(string $folder): FolderInterface
28+
public function findOrFail(string $path): FolderInterface
2929
{
30-
return $this->get($folder)->firstOrFail();
30+
return $this->get($path)->firstOrFail();
3131
}
3232

3333
/**
3434
* {@inheritDoc}
3535
*/
36-
public function create(string $folder): FolderInterface
36+
public function create(string $path): FolderInterface
3737
{
38-
$this->mailbox->connection()->create($folder);
38+
$this->mailbox->connection()->create($path);
3939

40-
return $this->find($folder);
40+
return $this->find($path);
4141
}
4242

4343
/**
4444
* {@inheritDoc}
4545
*/
46-
public function firstOrCreate(string $folder): FolderInterface
46+
public function firstOrCreate(string $path): FolderInterface
4747
{
48-
return $this->find($folder) ?? $this->create($folder);
48+
return $this->find($path) ?? $this->create($path);
4949
}
5050

5151
/**

src/FolderRepositoryInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ interface FolderRepositoryInterface
99
/**
1010
* Find a folder.
1111
*/
12-
public function find(string $folder): ?FolderInterface;
12+
public function find(string $path): ?FolderInterface;
1313

1414
/**
1515
* Find a folder or throw an exception.
1616
*/
17-
public function findOrFail(string $folder): FolderInterface;
17+
public function findOrFail(string $path): FolderInterface;
1818

1919
/**
2020
* Create a new folder.
2121
*/
22-
public function create(string $folder): FolderInterface;
22+
public function create(string $path): FolderInterface;
2323

2424
/**
2525
* Find or create a folder.
2626
*/
27-
public function firstOrCreate(string $folder): FolderInterface;
27+
public function firstOrCreate(string $path): FolderInterface;
2828

2929
/**
3030
* Get the mailboxes folders.

src/MessageQuery.php

Lines changed: 3 additions & 267 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,9 @@
2222
/**
2323
* @mixin \DirectoryTree\ImapEngine\Connection\ImapQueryBuilder
2424
*/
25-
class MessageQuery
25+
class MessageQuery implements MessageQueryInterface
2626
{
27-
use Conditionable, ForwardsCalls;
28-
29-
/**
30-
* The current page.
31-
*/
32-
protected int $page = 1;
33-
34-
/**
35-
* The fetch limit.
36-
*/
37-
protected ?int $limit = null;
38-
39-
/**
40-
* Whether to fetch the message body.
41-
*/
42-
protected bool $fetchBody = false;
43-
44-
/**
45-
* Whether to fetch the message flags.
46-
*/
47-
protected bool $fetchFlags = false;
48-
49-
/**
50-
* Whether to fetch the message headers.
51-
*/
52-
protected bool $fetchHeaders = false;
53-
54-
/**
55-
* The fetch order.
56-
*/
57-
protected string $fetchOrder = 'desc';
58-
59-
/**
60-
* Whether to leave messages fetched as unread by default.
61-
*/
62-
protected bool $fetchAsUnread = true;
63-
64-
/**
65-
* The methods that should be returned from query builder.
66-
*/
67-
protected array $passthru = ['toimap', 'isempty'];
27+
use Conditionable, ForwardsCalls, QueriesMessages;
6828

6929
/**
7030
* Constructor.
@@ -74,230 +34,6 @@ public function __construct(
7434
protected ImapQueryBuilder $query,
7535
) {}
7636

77-
/**
78-
* Handle dynamic method calls into the query builder.
79-
*/
80-
public function __call(string $method, array $parameters): mixed
81-
{
82-
if (in_array(strtolower($method), $this->passthru)) {
83-
return $this->query->{$method}(...$parameters);
84-
}
85-
86-
$this->forwardCallTo($this->query, $method, $parameters);
87-
88-
return $this;
89-
}
90-
91-
/**
92-
* Don't mark messages as read when fetching.
93-
*/
94-
public function leaveUnread(): static
95-
{
96-
$this->fetchAsUnread = true;
97-
98-
return $this;
99-
}
100-
101-
/**
102-
* Mark all messages as read when fetching.
103-
*/
104-
public function markAsRead(): static
105-
{
106-
$this->fetchAsUnread = false;
107-
108-
return $this;
109-
}
110-
111-
/**
112-
* Set the limit and page for the current query.
113-
*/
114-
public function limit(int $limit, int $page = 1): static
115-
{
116-
if ($page >= 1) {
117-
$this->page = $page;
118-
}
119-
120-
$this->limit = $limit;
121-
122-
return $this;
123-
}
124-
125-
/**
126-
* Get the set fetch limit.
127-
*/
128-
public function getLimit(): ?int
129-
{
130-
return $this->limit;
131-
}
132-
133-
/**
134-
* Set the fetch limit.
135-
*/
136-
public function setLimit(int $limit): static
137-
{
138-
$this->limit = max($limit, 1);
139-
140-
return $this;
141-
}
142-
143-
/**
144-
* Get the set page.
145-
*/
146-
public function getPage(): int
147-
{
148-
return $this->page;
149-
}
150-
151-
/**
152-
* Set the page.
153-
*/
154-
public function setPage(int $page): static
155-
{
156-
$this->page = $page;
157-
158-
return $this;
159-
}
160-
161-
/**
162-
* Determine if the body of messages is being fetched.
163-
*/
164-
public function isFetchingBody(): bool
165-
{
166-
return $this->fetchBody;
167-
}
168-
169-
/**
170-
* Determine if the flags of messages is being fetched.
171-
*/
172-
public function isFetchingFlags(): bool
173-
{
174-
return $this->fetchFlags;
175-
}
176-
177-
/**
178-
* Determine if the headers of messages is being fetched.
179-
*/
180-
public function isFetchingHeaders(): bool
181-
{
182-
return $this->fetchHeaders;
183-
}
184-
185-
/**
186-
* Fetch the body of messages.
187-
*/
188-
public function withFlags(): static
189-
{
190-
return $this->setFetchFlags(true);
191-
}
192-
193-
/**
194-
* Fetch the body of messages.
195-
*/
196-
public function withBody(): static
197-
{
198-
return $this->setFetchBody(true);
199-
}
200-
201-
/**
202-
* Fetch the body of messages.
203-
*/
204-
public function withHeaders(): static
205-
{
206-
return $this->setFetchHeaders(true);
207-
}
208-
209-
/**
210-
* Don't fetch the body of messages.
211-
*/
212-
public function withoutBody(): static
213-
{
214-
return $this->setFetchBody(false);
215-
}
216-
217-
/**
218-
* Don't fetch the body of messages.
219-
*/
220-
public function withoutHeaders(): static
221-
{
222-
return $this->setFetchHeaders(false);
223-
}
224-
225-
/**
226-
* Don't fetch the body of messages.
227-
*/
228-
public function withoutFlags(): static
229-
{
230-
return $this->setFetchFlags(false);
231-
}
232-
233-
/**
234-
* Set whether to fetch the flags.
235-
*/
236-
protected function setFetchFlags(bool $fetchFlags): static
237-
{
238-
$this->fetchFlags = $fetchFlags;
239-
240-
return $this;
241-
}
242-
243-
/**
244-
* Set the fetch body flag.
245-
*/
246-
protected function setFetchBody(bool $fetchBody): static
247-
{
248-
$this->fetchBody = $fetchBody;
249-
250-
return $this;
251-
}
252-
253-
/**
254-
* Set whether to fetch the headers.
255-
*/
256-
protected function setFetchHeaders(bool $fetchHeaders): static
257-
{
258-
$this->fetchHeaders = $fetchHeaders;
259-
260-
return $this;
261-
}
262-
263-
/**
264-
* Set the fetch order.
265-
*/
266-
public function setFetchOrder(string $fetchOrder): static
267-
{
268-
$fetchOrder = strtolower($fetchOrder);
269-
270-
if (in_array($fetchOrder, ['asc', 'desc'])) {
271-
$this->fetchOrder = $fetchOrder;
272-
}
273-
274-
return $this;
275-
}
276-
277-
/**
278-
* Get the fetch order.
279-
*/
280-
public function getFetchOrder(): string
281-
{
282-
return $this->fetchOrder;
283-
}
284-
285-
/**
286-
* Set the fetch order to 'ascending'.
287-
*/
288-
public function setFetchOrderAsc(): static
289-
{
290-
return $this->setFetchOrder('asc');
291-
}
292-
293-
/**
294-
* Set the fetch order to 'descending'.
295-
*/
296-
public function setFetchOrderDesc(): static
297-
{
298-
return $this->setFetchOrder('desc');
299-
}
300-
30137
/**
30238
* Execute an IMAP search request.
30339
*/
@@ -518,7 +254,7 @@ public function paginate(int $perPage = 5, $page = null, string $pageName = 'pag
518254
/**
519255
* Find a message by the given identifier type or throw an exception.
520256
*/
521-
public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid)
257+
public function findOrFail(int $id, ImapFetchIdentifier $identifier = ImapFetchIdentifier::Uid): MessageInterface
522258
{
523259
/** @var UntaggedResponse $response */
524260
$response = $this->uid($id, $identifier)->firstOrFail();

0 commit comments

Comments
 (0)