我有一个PHPUnit测试,循环遍历一个无效值数组,并断言每个函数都正确拒绝了.
例如,validateInput
仅当输入是字符串时才返回true,否则返回false.
public function testValidateInput()
{
$obj = new MyClass();
$data = [
null,
42,
21.21,
-24,
-12.12,
false,
array('key' => 'value'),
(object) 'value'
];
foreach ($data as $item){
$this->assertSame(false, $obj->validateInput($item));
}
}
Run Code Online (Sandbox Code Playgroud)
当测试失败时,我只得到行号 - 这对于所有值都是相同的,因为它在一个循环中.
Run Code Online (Sandbox Code Playgroud)1) MyClassTest::testValidateInput Failed asserting that true is identical to false. /home/jeff/MyClass/tests/MyClassTest.php:24
如何确定断言失败的值?
我正在使用Dingo API在Laravel 5.2中创建一个API,并且有一个控制器使用以下命令返回数据
return $this->response->paginator($rows, new SymptomTransformer, ['user_id' => $user_id]);
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何user_id
在SymptomTransformer中检索值!尝试了许多不同的方法并尝试了上课,但是我对Laravel和OOP还是比较陌生,因此如果有人可以将我指向正确的方向,将不胜感激。
以下是我的变压器课。
class SymptomTransformer extends TransformerAbstract
{
public function transform(Symptom $row)
{
// need to get user_id here
return [
'id' => $row->id,
'name' => $row->name,
'next_type' => $next,
'allow' => $allow
];
}
}
Run Code Online (Sandbox Code Playgroud) 有一种authorizeResource()
将特定策略应用于所有路由(索引路由除外)的方法。有没有办法只在特定路由上应用策略,类似于这个功能:
Route::resource('photo', 'PhotoController', ['only' => [
'index', 'show'
]]);
Run Code Online (Sandbox Code Playgroud) 我有一个问题,我需要获取拥有博物馆的画廊表和拥有博物馆的用户的所有图像(路径)。我得到了图像的路径,但这些与拥有博物馆的 user_id 无关。
因此,简要说明:
每个用户都拥有一个博物馆,一个博物馆有一个包含多个图像的画廊(图像 url 的路径)
五月表结构
我的画廊模型:
<?php
class Gallery extends \Eloquent {
protected $fillable = [];
public function museums() {
//return $this->belongsToMany('Museums', 'id');
return $this->belongsTo('Gallery', 'museum_id');
}
}
Run Code Online (Sandbox Code Playgroud)
我的博物馆模型
<?php
class Museum extends Eloquent {
protected $fillable = ['user_id', 'title', 'description'];
public function user()
{
return $this->belongsTo('User');
}
public function gallery()
{
//return $this->belongsToMany('Gallery', 'museum_id');
return $this->belongsToMany('Gallery');
}
}
Run Code Online (Sandbox Code Playgroud)
我的用户模型
public function museums()
{ …
Run Code Online (Sandbox Code Playgroud) 在Laravel 5上,在刀片模板上@yield
,只有当环境变量APP_DEBUG设置为true时,我才想要代码的一部分.刀片模板上的代码是:
@if(env('APP_DEBUG') == 1)
@yield('debugcontrols')
@endif
Run Code Online (Sandbox Code Playgroud)
但是无论我是否设置APP_DEBUG=false
了我的.env,该行将env('APP_DEBUG')
始终检索1,而所有其他环境变量将检索其正确的值.
如何获取APP_DEBUG环境变量?
请注意,所有其他环境变量都可以正确打印,例如,
APP_DEBUG=false
DB_HOST=localhost
Run Code Online (Sandbox Code Playgroud)
代码,
{{ env('DB_HOST') }}
{{ env('APP_DEBUG') }}
{{ Config::get('app.debug') }}
Run Code Online (Sandbox Code Playgroud)
会渲染,
localhost 1 1
Run Code Online (Sandbox Code Playgroud) 我正在开发一个函数来自动为每个视图获取资源(.css,.js).所以它可以说," http://mywebsite.com/displayitems ",/ home,/ about等.
但是自从我使用函数编写函数后$_SERVER['REQUEST_URI']
,当我有一条路由时,我想出了一个问题,就像路由/displayitems/1
中的"/ 1"一样.
那时候在Laravel 4.x我有一个很好的方法可以做到这一点,但遗憾的是它在Laravel 5.4中的工作方式不同.
我一直在网上搜索获得当前路线的好方法,但没有成功.问题是我必须忽略请求URL中的任何参数.
如果有人有线索,或者我做错了,并且有一种完全不同的,更好的方法吗?
PS我当前的功能:
public static function getAllRouteAssets() {
$route = $_SERVER['REQUEST_URI'];
if($route == "/") {
$tag = '<link href="' . asset("assets/css/pages/home.css") . '" rel="stylesheet" type="text/css"/>';
}
else {
// CSS
$tag = '<link href="' . asset("assets/css/pages" . $route . ".css") . '" rel="stylesheet" type="text/css"/>';
}
echo $tag;
//TODO: Check if file exists, homepage condition, js...
}
Run Code Online (Sandbox Code Playgroud) 我有这样的数据,,a,,c,,,,,i,j,k,,m,,,,,
我需要删除额外的逗号,所以它看起来像这样a,c,i,j,k,m
我正在使用MS SQL Server 2012
我正在使用Aurelia骨架,其中包含用于不同目的的各种项目设置,但它更像是一个关于如何使用git执行某些操作的一般问题,如下所述.
我希望能够将GitHub框架存储库中发布的更新合并到我实际工作的项目中.你会怎么做?
目前我刚刚在skeleton-typescript项目(我正在使用)中初始化了一个新的本地存储库,并将其连接到一个私有远程仓库以推送我的更改.但是通过这种设置,我正在使用我的项目特定更改来污染父存储库(远程指向Github上的aurelia-skeleton).
由于aurelia-skeleton远程存储库通常仅用于提取变化,因此进行某种单向跟踪将是完美的.
作为第二步,如何使用这样的设置创建拉取请求将会很有趣.在这种情况下,我想使用我在子存储库中所做的更改合并到aurelia远程的fork中...
在我的项目中,我使用的操作系统不同,一台是Mac,第二台是Windows。当我使用git时,所有更改都显示为整个文档更改。原因是这两个OS的行尾不同。我阅读了此https://help.github.com/articles/dealing-with-line-endings/并.gitattributes
在根文件夹中创建了一个文件,但问题仍然存在。这是我的.gitattributes
文件:
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.css text
*.html text
*.js text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不起作用,因为我之前曾尝试过对该文件进行很多配置。
我有以下代码:
$posts = $wp_query->posts;
foreach($posts as $post){
var_dump($post);
}
Run Code Online (Sandbox Code Playgroud)
这将抓取正在运行的查询的所有帖子并显示所有帖子信息。var_dump 看起来像这样:
object(WP_Post)#84 (24) {
["ID"]=> int(1190)
["post_author"]=> string(1) "1"
["post_date"]=> string(19) "2016-10-20 14:17:55"
["post_date_gmt"]=> string(19) "2016-10-20 03:17:55"
["post_content"]=> string(0) ""
["post_title"]=> string(21) "Chilled water systems"
["post_excerpt"]=> string(0) ""
["post_status"]=> string(7) "publish"
["comment_status"]=> string(6) "closed"
["ping_status"]=> string(6) "closed"
["post_password"]=> string(0) ""
["post_name"]=> string(21) "chilled-water-systems"
["to_ping"]=> string(0) ""
["pinged"]=> string(0) ""
["post_modified"]=> string(19) "2016-10-21 11:23:49"
["post_modified_gmt"]=> string(19) "2016-10-21 00:23:49"
["post_content_filtered"]=> string(0) ""
["post_parent"]=> int(1182)
["guid"]=> string(48) "http://siteurl.com"
["menu_order"]=> int(0) **
["post_type"]=> string(4) …
Run Code Online (Sandbox Code Playgroud) 我有一个angular 2项目,最初是用来与systemjs捆绑在一起的。
现在我想用webpack捆绑这个项目。
但是原始代码中有很多这样的字符串。如
我想将所有字符串替换为文件所在的绝对目录。原始时间,生产模式或开发模式下,此字符串将替换为路径字符串。
现在,我想在编译.ts文件之前使用webpack替换此字符串。我应该使用哪种插件?
例如:login.module.routing.ts
{path:'login',/ app / src / login#LoginModule},
我想在使用webpack编译之前替换。
例如:{path:'login',/ root / myproject / app / src / login#LoginModule},
非常感谢 !
我试图了解如何在Git中创建映射到我的开发过程的目录结构.
顺便说一句,我是Git的新手,但不是源代码控制.
我使用GitLab作为我的存储库管理器.
我已将我的存储库添加到GitLab并成功克隆了存储库.
我想要创建的开发过程如下:
主人| 完成| QA | INT
每当有人克隆存储库时,他们将自动看到这个分支结构并将在int
分支上工作.
我已经尝试运行命令,认为它会创建结构,但它不会出现(也许我错了).
git checkout -b Done master
git checkout -b QA Done
git checkout -b INT QA
git branch
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)Done * INT QA master
无论如何,我假设我错过了一些简单的东西(希望如此).
有没有人对如何设置这个简单的分支层次结构有任何见解?
谢谢