我在一个项目中使用理论(不是symfony)。在这个项目中,我还使用了phpstan,我同时安装了phpstan/phpstan-doctrine和phpstan/extension-installer。我的phpstan.neon是这样的
parameters:
level: 8
paths:
- src/
doctrine:
objectManagerLoader: tests/object-manager.php在test/Object-Manager.php中,它返回对返回实体管理器的函数的调用结果。
下面是创建实体管理器的代码
$database_url = $_ENV['DATABASE_URL'];
$isDevMode = $this->isDevMode();
$proxyDir = null;
$cache = null;
$useSimpleAnnotationReader = false;
$config = Setup::createAnnotationMetadataConfiguration(
[$this->getProjectDirectory() . '/src'],
$isDevMode,
$proxyDir,
$cache,
$useSimpleAnnotationReader
);
// database configuration parameters
$conn = [
'url' => $database_url,
];
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);当我运行vendor/bin/phpstan analyze时,会得到以下错误:
Internal error: An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name "postgres_db" to address: nodename nor servname provided, or not known之所以出现这种情况,是因为我使用的是docker,而我的数据库url是postgres://user:password@postgres_db/database,postgres_db是数据库容器的名称,所以主机名在docker容器中是已知的。
当我在容器内运行phpstan时,没有错误。
,那么有办法在码头外运行phpstan吗?因为我非常确信,当我推送代码时,github工作流会因为这个而失败
是否需要尝试访问数据库??
发布于 2022-02-21 14:57:11
我在phpstan主义的github上发表了一个问题,我有一个@jlherren答复解释道:
问题是,Doctrine需要知道它正在使用的DB服务器的哪个版本,以便实例化正确的AbstractPlatform实现,对于同一个DB供应商(例如,用于postgres的PostgreSQL94Platform或PostgreSQL100Platform,对于其他DB驱动程序,也有几种实现是可用的)。要自动检测该信息,它只需连接到DB并查询版本.
我刚刚更改了我的数据库网址:
DATABASE_URL=postgres://user:password@database_ip/database至:
DATABASE_URL=postgres://user:password@database_ip/database?serverVersion=14.2https://stackoverflow.com/questions/71034383
复制相似问题