-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add use import statements for PHP Snippets (#2000)
* Draft php imports in snippets * fix import paths for models and request builders php * add imports after opening php tag * fix request builder namespace paths * fix request builder namespace and path * do not transform imports parts to lowercase or snake case * replace . with \\ in requestbuilder namespace path * replace . with \\ in requestbuilder namespace path * remove double slashes on request builder path * fix replace dots with slashes on import paths * fix replace dots with slashes on import paths -change case * fix dot to slash replacement * fix dot to slash replacement * Update request builder path * Update request builder path - change casing * remove double slashes on request builder paths * remove equest builder name- use namespace only for imports * remove model name - use model namespace without fqcn * remove model name - use model namespace without fqcn * unit tests for php use statements * add unit tests for use statements in php snippets * move tests to php generator test * fix code coverage * remove request builder imports - namespaces are enough * add request builder filename to import * add model and request builder class name import * fix tests include class names on imports * fix import class names * improve code readability * fix indentation * update classname in imports * fix casing for request builder name * fix casing for request builder name * Update tests to reflect request builde class names * remove duplicate unit tests * fix failing tests * fix failing tests * Convert importsgenerator to static class * Fix snippet import tests * remove duplcate unit tests
- Loading branch information
1 parent
656e5c4
commit 94e5641
Showing
6 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
CodeSnippetsReflection.OpenAPI.Test/PhpImportGeneratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using CodeSnippetsReflection.OpenAPI.LanguageGenerators; | ||
using Xunit; | ||
|
||
namespace CodeSnippetsReflection.OpenAPI.Test; | ||
|
||
public class PhpImportTests : OpenApiSnippetGeneratorTestBase | ||
{ | ||
private readonly PhpGenerator _generator = new(); | ||
|
||
[Fact] | ||
public async Task GeneratesRequestBuilderImports() | ||
{ | ||
using var requestPayload = new HttpRequestMessage(HttpMethod.Get, $"{ServiceRootUrl}/me/calendar/events?$filter=startsWith(subject,'All')"); | ||
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata()); | ||
var result = _generator.GenerateCodeSnippet(snippetModel); | ||
Assert.Contains("use Microsoft\\Graph\\GraphServiceClient;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Users\\Item\\Calendar\\Events\\EventsRequestBuilderGetRequestConfiguration;", result); | ||
} | ||
|
||
[Fact] | ||
public async Task GenerateModelImports(){ | ||
var bodyContent = @"{ | ||
""displayName"": ""New display name"" | ||
}"; | ||
using var requestPayload = new HttpRequestMessage(HttpMethod.Patch, $"{ServiceRootUrl}/applications/{{id}}") | ||
{ | ||
Content = new StringContent(bodyContent, Encoding.UTF8, "application/json") | ||
}; | ||
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata()); | ||
var result = _generator.GenerateCodeSnippet(snippetModel); | ||
Assert.Contains("use Microsoft\\Graph\\GraphServiceClient;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Models\\Application;", result); | ||
|
||
} | ||
[Fact] | ||
public async Task GenerateComplexModelImports(){ | ||
var bodyContent = @"{ | ||
""subject"": ""Annual review"", | ||
""body"": { | ||
""contentType"": ""HTML"", | ||
""content"": ""You should be proud!"" | ||
}, | ||
""toRecipients"": [ | ||
{ | ||
""emailAddress"": { | ||
""address"": ""[email protected]"" | ||
} | ||
} | ||
], | ||
""extensions"": [ | ||
{ | ||
""@odata.type"": ""microsoft.graph.openTypeExtension"", | ||
""extensionName"": ""Com.Contoso.Referral"", | ||
""companyName"": ""Wingtip Toys"", | ||
""expirationDate"": ""2015-12-30T11:00:00.000Z"", | ||
""dealValue"": 10000 | ||
} | ||
] | ||
}"; | ||
using var requestPayload = new HttpRequestMessage(HttpMethod.Post, $"{ServiceRootUrl}/me/messages/") | ||
{ | ||
Content = new StringContent(bodyContent, Encoding.UTF8, "application/json") | ||
}; | ||
var snippetModel = new SnippetModel(requestPayload, ServiceRootUrl, await GetV1SnippetMetadata()); | ||
var result = _generator.GenerateCodeSnippet(snippetModel); | ||
Assert.Contains("use Microsoft\\Graph\\GraphServiceClient;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Models\\Message;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Models\\ItemBody;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Models\\Recipient;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Models\\EmailAddress;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Models\\Extension;", result); | ||
Assert.Contains("use Microsoft\\Graph\\Generated\\Models\\OpenTypeExtension;", result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters