security = $this->createMock(Security::class); $this->queryBuilder = $this->createMock(QueryBuilder::class); $this->user = $this->createMock(Access::class); $this->organization = $this->createMock(Organization::class); $this->extension = new CurrentEducationNotationConfigExtension($this->security); } public function testSupportsReturnsTrueForEducationNotationConfigClass() { $this->assertTrue($this->extension->supports(EducationNotationConfig::class, null)); } public function testSupportsReturnsFalseForOtherClasses() { $classes = ['OtherClass', Access::class]; foreach ($classes as $class) { $this->assertFalse($this->extension->supports($class, null)); } } public function testAddWhere() { $this->user->method('getOrganization')->willReturn($this->organization); $this->security->method('getUser')->willReturn($this->user); $this->queryBuilder->method('getRootAliases')->willReturn(['o']); $this->queryBuilder->expects($this->once()) ->method('andWhere') ->with('o.organization = :organization') ->willReturn($this->queryBuilder); $this->queryBuilder->expects($this->once()) ->method('setParameter') ->with('organization', $this->organization) ->willReturn($this->queryBuilder); $reflection = new \ReflectionClass($this->extension); $method = $reflection->getMethod('addWhere'); $method->setAccessible(true); $method->invoke($this->extension, $this->queryBuilder, EducationNotationConfig::class, null); } public function testAddWhereWithNullUser() { $this->security->method('getUser')->willReturn(null); $this->queryBuilder->method('getRootAliases')->willReturn(['o']); $this->queryBuilder->expects($this->never()) ->method('andWhere'); $this->queryBuilder->expects($this->never()) ->method('setParameter'); $reflection = new \ReflectionClass($this->extension); $method = $reflection->getMethod('addWhere'); $method->setAccessible(true); $method->invoke($this->extension, $this->queryBuilder, EducationNotationConfig::class, null); } public function testAddWhereWithNullOrganization() { $this->user->method('getOrganization')->willReturn(null); $this->security->method('getUser')->willReturn($this->user); $this->queryBuilder->method('getRootAliases')->willReturn(['o']); $this->queryBuilder->expects($this->never()) ->method('andWhere'); $this->queryBuilder->expects($this->never()) ->method('setParameter'); $reflection = new \ReflectionClass($this->extension); $method = $reflection->getMethod('addWhere'); $method->setAccessible(true); $method->invoke($this->extension, $this->queryBuilder, EducationNotationConfig::class, null); } }