我按照站点使用一次性数据库教程测试Symfony应用程序.我在我的测试用例中添加了Fixtures,并且在SetUp期间没有出现错误.如果我在灯具中添加一个错误(例如,将一个nullable = false字段留空),则会显示错误,因此该代码肯定会被执行.
我的配置:
doctrine:
dbal:
default_connection: memory
connections:
memory:
driver: pdo_sqlite
memory: true
charset: UTF8
Run Code Online (Sandbox Code Playgroud)
我的WebTestCase中的SetUp:
protected function setUp() {
parent::setUp();
self::bootKernel();
DatabasePrimer::prime(self::$kernel);
$this->loadFixtures([
'AppBundle\DataFixtures\ORM\UserData',
'AppBundle\DataFixtures\ORM\ArtistData'
]);
}
Run Code Online (Sandbox Code Playgroud)
然而,在我的WebTestCase中,似乎没有表存在.输出抛出一个Doctrine异常,说我的表不存在.
SQLSTATE[HY000]: General error: 1 no such table: my_user_table
Run Code Online (Sandbox Code Playgroud)
如果我在文件中切换到sql_lite,一切正常,没有任何其他更改:
dbal:
default_connection: file
connections:
file:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
charset: UTF8
Run Code Online (Sandbox Code Playgroud)
任何人都有成功的说教程或使用sqlite内存数据库进行单元测试,并有任何提示或想法?
更新: 我将我的安装程序更改为此以确保内核不会在其间关闭.它没有帮助:
parent::setUp();
$this->client = $this->getClient();
MemoryDbPrimer::prime(self::$kernel);
$this->loadFixtures([
'AppBundle\DataFixtures\ORM\UserData',
'AppBundle\DataFixtures\ORM\ArtistData'
]);
Run Code Online (Sandbox Code Playgroud) 我有一个学说实体,有一个实体(儿童)的集合.现在我想计算实体并打印出计数.像这样的东西:
<div class="item">
<h1>{{ object.name }}</h1>
<div class="childrenCount">children {% count (object.children) %}</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我发现了一些不起作用的例子(例如使用"计数"过滤器导致"未找到过滤器"错误).
我的学说有问题.我喜欢缓存,但是如果我更新实体并刷新,那么doctrine2是否应该能够清除它的缓存?否则缓存对我来说用处很少,因为这个项目有很多交互,我总是要为每个查询禁用缓存.如果缓存总是向他们显示旧的缓存版本,则用户将看不到他们的交互.
它有什么方法吗?
我正在编写一个小小的迁移脚本,我只是尝试更新一个元素的一个属性.我需要的结果在本地环境中没有表示,所以我需要的是一个非常简单的SQL(这里是Oracle)处理程序,我可以迭代并返回一个数组.
这可能与学说有关吗?
即我想要这样做:
$query = "SELECT t2.status FROM t2 LEFT JOIN t1 ON t1.id = t2.foreinkey";
$iterator = $connection->execute($query)->iterate();
foreach ($iterator as $array) {
// do something with an associative array
}
Run Code Online (Sandbox Code Playgroud)
更新/解决方案:通过Corbin的提示,我想出了这个解决方案,效果非常好:
$query = "SELECT t2.status FROM t2 LEFT JOIN t1 ON t1.id = t2.foreinkey";
$iterator = $connection->query($query);
while (is_object($iterator) AND ($array = $iterator->fetch()) !== FALSE) {
// do something with an associative array
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将Symfony2,KnpGaufetteBundle和Amazon S3结合起来.从KnpGaufette Bundle我得到一个xml定义用于我的配置.但它是在xml中,我的配置是在yml中.不知怎的,我无法理解它.如何在yml中定义以下变量?他们是什么意思?
<service id="acme.s3" class="AmazonS3">
<argument type="collection">
<argument key="key">%acme.aws_key%</argument>
<argument key="secret">%acme.aws_secret_key%</argument>
</argument>
</service>
<service id="acme.s3.adapter" class="Gaufrette\Adapter\AmazonS3">
<argument type="service" id="acme.s3"></argument>
<argument>%acme.s3.bucket_name%</argument>
</service>
<service id="acme.fs" class="Gaufrette\Filesystem">
<argument type="service" id="acme.s3.adapter"></argument>
</service>
Run Code Online (Sandbox Code Playgroud)
所以,要实际让它工作,不仅我们必须在yml中放下配置(已经由chmeliuk解决 - >谢谢),但我们还需要为curl配置cacert.pem文件.你可以在这里找到一个合适的:http://curl.haxx.se/ca/cacert.pem
现在把它放在你想要的任何地方,然后使用以下行和附加的certificate_authority条目:
services:
acme.s3:
class: AmazonS3
arguments:
options: { key: %acme.aws_key%, secret: %acme.aws_secret_key%, certificate_authority: "pathWhereYouDidPutThisFile/cacert.pem" }
acme.s3.adapter:
class: Gaufrette\Adapter\AmazonS3
arguments:
service: @acme.s3
bucket_name: %acme.s3.bucket_name%
acme.fs:
class: Gaufrette\Filesystem
arguments:
adapter: @acme.s3.adapter
Run Code Online (Sandbox Code Playgroud)
这解决了CA Cert cURL Error 60,否则您可能会遇到此问题.
我试图使用sinon,jasmine和$ q来存根方法.我希望该方法返回我的假数据.
问题是定义的then语句永远不会被调用,我无法弄清楚原因.这已经是一个简化版本,但它仍然无法正常工作:
Steven Stub is called调用控制台日志then回调被调用这是我的代码
var p = {steven: function() {console.log('original steven');}},
pStub = sinon.stub(p, 'steven', function(){
console.log('Steven Stub is called');
var defer = $q.defer();
defer.resolve({item: 5});
return defer.promise;
});
var promise = p.steven();
promise.then(
function(data){console.log('Peter?');},
function(data) {console.log('ERROR?');},
function(data) {console.log('progress?');});
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我正在编写一个小工具,我需要检查是否定义了某个ng-template.我的所有模板定义如下:
<script type="text/ng-template" id="example.html">...</script>
Run Code Online (Sandbox Code Playgroud)
所以通过$ http检查文件是否存在对我来说不起作用.如何检查所述模板是否已定义?我到目前为止看到的唯一选择是检查DOM:
if(angular.element.find('script#example.html').length > 0) { ...
Run Code Online (Sandbox Code Playgroud)
...但我真的很喜欢一个不需要检查DOM的更好的解决方案.
我真的不明白我在做错了什么:
模板:
<embed [src]="pdfUrl" width="500" height="100%" type='application/pdf'>
Run Code Online (Sandbox Code Playgroud)
类:
pdfURL;
constructor(private domSanitizer : DomSanitizer) {}
ngOnInit() {
this.pdfUrl = this.domSanitizer.bypassSecurityTrustUrl('http://example.com/pdf.pdf')
}
Run Code Online (Sandbox Code Playgroud)
这实际上不会加载<embed>但不会抛出错误.
我尝试使用SafeUrltype on pdfURL和with bypassSecurityTrustResourceUrl().该<embed>标签接收正确的URL,但不显示任何内容.
我有一个只有语言环境的路由,没有任何其他信息(起始页):
homepage:
pattern: /{_locale}/
defaults: { _controller: OurStartBundle:Default:index }
Run Code Online (Sandbox Code Playgroud)
如果我直接调用该路由它(即:localhost/de_DE /),但如果我转发它会抛出错误:
无法解析控制器名称"/app_dev.php/de_DE/".
我使用这样的Controller方法转发:
$locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
return $this->forward($this->generateUrl('homepage', array('_locale' => $locale)));
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么这不起作用?
我按照本教程安装了带有FOSUserBundle的SonataAdmin.
现在我不断收到此错误消息:没有为Application\Sonata\UserBundle\Entity\User类定义实体管理器
但是我如何设置/传递EntityManager?我没有找到任何关于配置它或任何关于此错误意味着什么的提示.有人帮忙吗?
编辑#1:
正如所要求的那样,到目前为止,这是我在config.yml中为sonata所拥有的内容:
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
Run Code Online (Sandbox Code Playgroud)
编辑#2:
我为Doctrine2 ORM Admin添加了实体管理器配置部分,在文档中提到如果保留为null,则应该使用默认值.不过,它并没有解决我的问题.
sonata_doctrine_orm_admin:
# default value is null, so doctrine uses the value defined in the configuration
entity_manager: '@doctrine.orm.entity_manager'
Run Code Online (Sandbox Code Playgroud)
编辑#3: 我确实将auto_mapping设置为true,即使你默认也是如此.仍然没有解决这个问题.
我试图登陆我的弧形补丁.我是最新的原点/主人,我的补丁被审查和接受.在phahicator网站上说:Next Step arc land 'arcpatch-D37'.但如果我使用arc patch D37然后arc land我遇到问题.
它拉开了:
Switched back to branch ?[1marcpatch-D37?[m.
[2014-04-29 14:06:50] EXCEPTION: (CommandException) Command failed with error #1
28!
COMMAND
git pull --ff-only --no-stat
STDOUT
(empty)
STDERR
fatal: Not possible to fast-forward, aborting.
at [D:\arcanist\libphutil\src\future\exec\ExecFuture.php:398]
Run Code Online (Sandbox Code Playgroud)
我尝试先拉,没有问题/冲突.不知道该做什么/下一步尝试.
我写了一个自定义的表单验证器,但errors它只是有"_isScalar": false, "source": { "_isScalar": false, "source": { "_isScalar": false, "source": {"_isScalar": false}, "operator": {}}, "operator": {"total": 1}并且表单永远不会有效。
这是我的验证器:
export function asyncEmailValidator(): AsyncValidatorFn {
return (control: AbstractControl): Observable<ValidationErrors | null> => {
return of(control.value).pipe(
map(res => {
return res && res.indexOf('example.de') < -1 ? { eMailUnavailable: true } : null;
}),
take(1), finalize(() => {})
);
};
}
Run Code Online (Sandbox Code Playgroud)
这是我如何使用它:
emailFormControl = new FormControl('', [
Validators.required,
Validators.email,
asyncEmailValidator()
]);
Run Code Online (Sandbox Code Playgroud)
从调试中,我发现我检查 example.de 的地图块从未到达过,我不明白为什么。在显示内部返回之前使用和输出函数本身。
我在网上的多个示例中看到了这种结构,但它似乎对我不起作用。
我在用 @angular/forms 10.0.14
angular angular-reactive-forms angular-forms angular2-form-validation
doctrine-orm ×3
symfony ×3
angular ×2
angularjs ×2
php ×2
symfony-2.1 ×2
amazon-s3 ×1
arcanist ×1
caching ×1
curl ×1
doctrine ×1
git ×1
iteration ×1
locale ×1
native ×1
oracle ×1
phabricator ×1
phpunit ×1
promise ×1
sinon ×1
sonata-admin ×1
sqlite ×1
templates ×1
twig ×1
url-routing ×1