WuLaLa Note

  • Home

  • About

  • Tags

  • Categories

  • Archives

composer-version版本

Posted on 2018-07-25
item version Range
Exact Match 1.23 1.23
Wildcard Range 1.0.* >=1.0 且 <1.1
Hyphen Range 1.0 - 2.0 >=1.0.0 且 <2.1
Tilde Operator ~1.2 >=1.2 且 <2.0
Caret Operator ^1.2.3
^0.3
>=1.2.3 且 <2.0
>=0.3.0 且 <0.4.0
Stability Flags @sable dev > alpha > beta > RC > stable
預設抓 stable,但可用@指定

Laravel-PHPUnit沒辦法Mock物件

Posted on 2018-07-25 | In 後端 , PHP , Laravel

Laravel專案中寫測試,遇到怎樣都沒辦法Mock其他物件,原因可能是這個物件早就被實現了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class ComboCategoryServiceTest extends TestCase
{
private $combo;
private $service;

public function setUp()
{
parent::setUp();
$this->combo = factory(ComboCategory::class)->create(['id' => 1]);
$this->service = app()->make(\App\Services\ComboCategoryService::class);
}

public function testSearchByFrontForCombo()
{
$mockHotel = Mockery::mock(\App\Repositories\HotelRepository::class);
$this->app->instance(\App\Repositories\HotelRepository::class, $mockHotel);
$mockHotel->shouldReceive('findByDomainOrFail')
->andReturn((object)['id' => 2])
->once();

//Mock其他物件之後,再make 一次
// $this->service = app()->make(ComboCategoryService::class);

$inputs = [
'domain' => get_domain(),
'combo_category' => $this->combo->id
];

$result = $this->service->searchByFrontForCombo($inputs);
$this->assertEquals($this->combo->id, $result->first()->id);
}
}

這個function會呼叫findByDomainOrFail,但是在這裡執行的時候,其實他都沒有被Mock

這是因為早在setUp早就實現ComboCategoryService:class,此建構子又實現HotelRepository::class

在這之後怎麼Mock,instance都沒有用。

結論:要在呼叫之前就Mock,instance,或是再實現一次方法。

1
$this->service = app()->make(ComboCategoryService::class);

Git小技巧

Posted on 2018-07-17 | In 工具 , Local

Git小技巧

如何同時推二個不同的儲存庫(Repository)

由於在家工作需要打VPN到公司來,很不方便。
所以在公司推專案到GitLab的時候,同時推到自己的Dropbox,這樣在家就可以從Dropbox存取專案,完成工作之後,到公司再從Dropbox下載專案推到公司的GitLab。

Read more »

Laravel套件:Debugbar

Posted on 2018-07-15 | Edited on 2018-07-16 | In 後端 , PHP , Laravel

https://github.com/barryvdh/laravel-debugbar/tree/2.4

Laravel 版本 < 5.5

Read more »

Git 教學

Posted on 2018-07-15 | Edited on 2018-07-16 | In 工具 , Local

https://git-scm.com/

Git 教學

安裝篇

下載Git

https://git-scm.com/downloads

  1. 安裝過程 next下一步到底。
  2. 安裝完成之後,可以找到 「Git Bash」
Read more »

PHP 小技巧

Posted on 2018-07-15 | Edited on 2018-07-16 | In 後端 , PHP

收集關於PHP的小技巧

重構長 If 語句

1
2
3
4
5
6
7
8
9
// Good
if (in_array($a, ['val_1', 'val_2', 'val_3'])) {
// 執行方法
}

// Bad
if ($a === 'val_1' || $a === 'val_2' || $a === 'val_3') {
// 執行動作
}
Read more »

LINE Notify 通知

Posted on 2018-07-15 | Edited on 2018-07-16 | In API

LINE Notify是一項非常方便的服務,用戶可以透過LINE接收GitHub、IFTTT及Mackerel等網站服務的提醒。

透過LINE接收其他網站服務通知
與網站服務連動完成後,LINE所提供的官方帳號「LINE Notify」將會傳送通知。
不僅可與多個服務連動,也可透過LINE群組接收通知。

Read more »

Hexo網誌框架 教學

Posted on 2018-07-15 | Edited on 2018-07-16 | In 工具 , Server

https://hexo.io/zh-tw/index.html

快速、簡單且強大的網誌框架

安裝Hexo Server

1
2
$ npm install -g hexo-cli
$ npm install hexo-server --save

詳細設定請參考:https://hexo.io/zh-tw/docs/index.html

啟動Hexo Server

1
$ hexo s -p 8080

s (server):啟動伺服器

-p (–port):設定你要的port

Read more »

You New Post

Posted on 2018-07-08 | Edited on 2018-07-16

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

YuWin

PHPer

9 posts
7 categories
11 tags
© 2018 YuWin
Powered by Hexo v3.7.1
|
Theme — NexT.Gemini v6.3.0